ldc-crm/app/Jobs/UpdateCustomerLastConnection.php
2023-06-30 12:51:21 +02:00

63 lines
1.5 KiB
PHP

<?php
namespace App\Jobs;
use App\Models\Customer;
use App\Models\CustomerLogin;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Carbon;
/**
* @codeCoverageIgnore
*/
class UpdateCustomerLastConnection implements ShouldQueue
{
use Dispatchable;
use InteractsWithQueue;
use Queueable;
use SerializesModels;
/** @var \Illuminate\Support\Carbon */
protected $date = null;
/** @var \App\Models\Customer */
protected $customer = null;
/** @var \App\Models\CustomerLogin */
protected $customerLogin = null;
/**
* Create a new job instance.
*
* @param \App\Models\Customer $customer
* @param \App\Models\CustomerLogin $customerLogin
* @param \Illuminate\Support\Carbon $date
* @return void
*/
public function __construct(
Customer $customer,
CustomerLogin $customerLogin,
Carbon $date
) {
$this->date = $date;
$this->customer = $customer;
$this->customerLogin = $customerLogin;
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
if ($this->customerLogin->last_connection < $this->date) {
$this->customerLogin->last_connection = $this->date;
$this->customer->logins()->save($this->customerLogin);
}
}
}