我想在我的控制器中排隊函數的一部分,主要是因爲它訪問第三方API並從所述請求計算某些信息。我也想這樣做來增加我對隊列的瞭解!Laravel - 將函數的一部分轉換爲排隊語句
,我想排隊的代碼是:
,將需要與此if statement
是$postcode
和$clinic ID
(這是上面的語句,想通了)推動的唯一變量。
if($clinic->postcode != $postcode)
{
$client = new Client([ 'base_uri' => 'https://api.postcodes.io/','timeout' => 2.0, 'verify' => false ]);
$response = $client->get('postcodes/'.$postcode)->getBody();
$input = json_decode($response);
$clinic->latitude = $input->result->latitude;
$clinic->longitude = $input->result->longitude;
$clinic->save();
}
到目前爲止,我已經創建了queue
表和遷移它。
我然後跑了命令:php artisan make:job GetClinicLatAndLongPoints --queued
我的問題是,我怎麼可以把這個功能GetClinicLatAndLongPoints
裏面包括通過這兩個變量在這樣做呢?
我到目前爲止有:
public function handle(Clinic $clinic, $postcode)
{
}
但我不能確定如何佈置的事情了!任何指導將非常感激。
你使用的是什麼版本的laravel,你同時標記了兩個!大聲笑 – Luceos
哎呀,對不起!我已經刪除了Laravel 4.我正在使用最新的Laravel 5.1。*! – Ben
您是否嘗試將它粘貼到您的句柄函數中?還要確保你的隊列正在運行('php artisan queue:listen') – Luceos