Sfoglia il codice sorgente

upload Console command

yulya_Shabanova 1 anno fa
parent
commit
f359d73343
2 ha cambiato i file con 91 aggiunte e 0 eliminazioni
  1. 41 0
      app/Kernel.php
  2. 50 0
      app/earlyPublication.php

+ 41 - 0
app/Kernel.php

@@ -0,0 +1,41 @@
+<?php
+
+namespace App\Console;
+
+use Illuminate\Console\Scheduling\Schedule;
+use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
+
+class Kernel extends ConsoleKernel
+{
+    /**
+     * The Artisan commands provided by your application.
+     *
+     * @var array
+     */
+    protected $commands = [
+        //
+    ];
+
+    /**
+     * Define the application's command schedule.
+     *
+     * @param  \Illuminate\Console\Scheduling\Schedule  $schedule
+     * @return void
+     */
+    protected function schedule(Schedule $schedule)
+    {
+        // $schedule->command('inspire')->hourly();
+    }
+
+    /**
+     * Register the commands for the application.
+     *
+     * @return void
+     */
+    protected function commands()
+    {
+        $this->load(__DIR__.'/Commands');
+
+        require base_path('routes/console.php');
+    }
+}

+ 50 - 0
app/earlyPublication.php

@@ -0,0 +1,50 @@
+<?php
+
+namespace App\Console\Commands;
+use App\Models\Post;
+
+use Illuminate\Console\Command;
+
+class earlyPublication extends Command
+{
+    /**
+     * The name and signature of the console command.
+     *
+     * @var string
+     */
+     protected $signature = 'publish:content';
+
+     /**
+     * The console command description.
+     *
+     * @var string
+     */
+     protected $description = 'Early publication';
+
+    /**
+     * Create a new command instance.
+     *
+     * @return void
+     */
+    public function __construct()
+    {
+        parent::__construct();
+    }
+
+    /**
+     * Execute the console command.
+     *
+     * @return int
+     */
+    public function handle()
+    {
+        $posts = Post::where('created_at', '<=', now())->get();
+
+        foreach ($posts as $post) {
+            $post->created_at = now();
+            $post->save();
+        }
+
+        $this->info('Dates have been changed.');
+    }
+}