Azərbaycan English
Loading...

 1. İlk öncə TestLog.php custom console command yaradırırq.(php artisan make:command TestLog)

<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;
use Illuminate\Support\Facades\Log;

class TestLog extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'rahim:logger';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Command description';

    /**
     * Execute the console command.
     */
    public function handle(): void
    {
        Log::debug('Rahim log etdi :'.date('Y-m-d H:i:s'));

        $this->info('Log yazıldı');
    }
}

2. Bu commandı app/Concole/Kernel.php -də qeydiyyatdan keçiririk.

<?php

namespace App\Console;

use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;

class Kernel extends ConsoleKernel
{
    /**
     * Define the application's command schedule.
     */
    protected function schedule(Schedule $schedule): void
    {
         $schedule->command('rahim:logger');
    }

    /**
     * Register the commands for the application.
     */
    protected function commands(): void
    {
        $this->load(__DIR__.'/Commands');

        require base_path('routes/console.php');
    }
}

3. Proyekti hostingerə deploy edirik.

4. Cron Job tipi olaraq PHP seçirik.

5.Command to run* inputuna öz path əlavə edirik: 

/usr/bin/php /home/u2xxxxx/full_domain_path/artisan schedule:run

6. Daha sonra çalışma intervalını daxil edirik.

Nəticə

by Rahim Süleymanov | Dec 19, 2023