Laravel-Cron Job Scheduler未保存到数据库

时间:2019-09-07 19:29:27

标签: laravel api guzzle

我正在编写一个cron作业,它将使用Guzzle和Laravel-5.8将外部api保存到我的数据库中。外部api是GET请求。

我检查了日志,但是什么都没有

模型

<?php

namespace App;
use App\ClientData;

use Illuminate\Database\Eloquent\Model;

class ClientData extends Model
{
    protected $table = 'clients';

    protected $fillable = [
        'client_id' ,
        'client_name',
        'search_name',
        'posting_group',
        'staff_no',
        'address1',
        'address2',
    ];    

}

app \ console \ Commands \ clientdataupdat.php

<?php

namespace App\Console\Commands;
use Illuminate\Console\Command;


use App\ClientData;
use Carbon\Carbon;

use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
use GuzzleHttp\Exception\GuzzleException;
use GuzzleHttp;
use GuzzleHttp\Client;

class clientdataupdate extends Command {


    protected $signature = 'command:clientdataupdate';

    protected $description = 'Client Data Update';

    public function __construct() {
        parent::__construct();
    }


    public function handle() {

        $client = new GuzzleHttp\Client();
        $result = $client->request('GET','https://api.bbasdf.net/clients/allclients');

        return $result->getBody(); 

        $clients = json_decode($result, true);

        foreach($clients as $client) {
            ClientData::updateOrCreate([
            'client_id' => $client->ClientID,
        ],
        [
            'client_name' => $client->ClientName,
            'search_name' => $client->SearchName,
            'posting_group' => $client->PostingGroup,
            'staff_no' => $client->StaffNo,
            'address1' => $client->Address1,
            'address2' => $client->Address2,
            ]);
        }       

    }
}

app \ console \ Kernel.php

<?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 = [
        //registering command
        'App\Console\Commands\clientdataupdate',
    ];

    /**
     * Define the application's command schedule.
     *
     * @param  \Illuminate\Console\Scheduling\Schedule  $schedule
     * @return void
     */
    protected function schedule(Schedule $schedule)
    {

         $schedule->command('command:clientdataupdate')
                 ->everyFiveMinutes();
    }

    protected function commands()
    {
        require base_path('routes/console.php');
    }
}

我希望cron作业每五分钟保存到我的本地数据库中,但是没有任何反应。

0 个答案:

没有答案