laravel-events

Laravel - Set queue delay dynamically for event listener

谁说我不能喝 提交于 2020-12-15 07:01:29
问题 Based on the documentation of Laravel to delay the job, we can add a $delay properties on the listener class (https://laravel.com/docs/8.x/events). I am trying to customize the $delay time in seconds that based on my start time and end time. From documentation which it's work fine: /** * The time (seconds) before the job should be processed. * * @var int */ public $delay = 60; I am trying to: public $delay; public function __construct ($event) { $this->delay= $event->seconds; } and I tried

Laravel - Set queue delay dynamically for event listener

*爱你&永不变心* 提交于 2020-12-15 07:01:27
问题 Based on the documentation of Laravel to delay the job, we can add a $delay properties on the listener class (https://laravel.com/docs/8.x/events). I am trying to customize the $delay time in seconds that based on my start time and end time. From documentation which it's work fine: /** * The time (seconds) before the job should be processed. * * @var int */ public $delay = 60; I am trying to: public $delay; public function __construct ($event) { $this->delay= $event->seconds; } and I tried

Laravel check if updateOrCreate performed update

点点圈 提交于 2020-06-11 16:51:28
问题 I have the following code in my controller: for($i=0; $i<$number_of_tourists; $i++) { $tourist = Tourist::updateOrCreate(['doc_number' => $request['doc_number'][$i]], $tourist_to_update); } each time "updateOrCreate" works, it does 1 of 3 things: 1) updates model instanse OR 2) creates and saves a new one OR 3) leaves everything unchanged (if model with such values already exists). I need to check if 'updateOrCreate' has done exactly 1 (updated) and then execute some code. How can I do it?

How to implement eloquent 'saving' event for all models , not individually

寵の児 提交于 2020-01-23 20:48:32
问题 Based on documentation of laravel eloquent event, all the eloquent event are triggered individually based on each model, is there any way to use 'creating' event or any other eloquent event to be triggered by all the Models For example , if any Models is created , event A is triggered 回答1: Listen for the Eloquent creating event that is fired. It is a 'string' event still not an object so you can do some ... wildcard matching here. This is the string of the events that are fired from Eloquent:

Laravel Eloquent Events - implement to save model if Updated

一世执手 提交于 2019-12-31 07:06:33
问题 I have such code in the controller: for($i=0; $i<$number_of_tourists; $i++) { $tourist = Tourist::updateOrCreate(['doc_number' => $request['doc_number'][$i]], $tourist_to_update); } so, the updateOrCreate method can 1) Update record, 2) Create a new one 3) Leave record untouched if $tourist_to_update equals to what's already in the DB. I want to save $tourist_to_update into $array[] only when a record in 'tourist" table is being updated (not when a new record created or nothing changes). As I

Laravel Broadcast - Combining multiple middleware (web, auth:api)

末鹿安然 提交于 2019-12-08 01:45:06
问题 I am using Laravel Event Broadcast and Pusher to utilize websockets both on my API and Web. If I try them individually, both work fine. What I mean is: Broadcast::routes(['middleware' => 'web']); // this works for my Laravel website Broadcast::routes(['middleware' => 'auth:api']); // this works for my api However, if I want to use both at the same time like this: Broadcast::routes(['middleware' => ['auth:api', 'web']]); // doesn't work ... it crashes for both, which I suspect that it is

How to implement eloquent 'saving' event for all models , not individually

我与影子孤独终老i 提交于 2019-12-06 15:59:43
Based on documentation of laravel eloquent event , all the eloquent event are triggered individually based on each model, is there any way to use 'creating' event or any other eloquent event to be triggered by all the Models For example , if any Models is created , event A is triggered Listen for the Eloquent creating event that is fired. It is a 'string' event still not an object so you can do some ... wildcard matching here. This is the string of the events that are fired from Eloquent: "eloquent.{$event}: ".static::class So you could listen for "eloquent.creating: *" to catch all those