38 lines
961 B
PHP
38 lines
961 B
PHP
<?php
|
|
|
|
namespace App\Listeners;
|
|
|
|
use App\Events\ContractToTerrain;
|
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
use Illuminate\Queue\InteractsWithQueue;
|
|
|
|
class AddContractToTerrain implements ShouldQueue
|
|
{
|
|
/**
|
|
* Create the event listener.
|
|
*/
|
|
public function __construct()
|
|
{
|
|
//
|
|
}
|
|
|
|
/**
|
|
* Handle the event.
|
|
*/
|
|
public function handle(ContractToTerrain $event): void
|
|
{
|
|
$contract = $event->contract;
|
|
$segment = $event->segment->where('name', 'terrain')->firstOrFail();
|
|
|
|
if($segment) {
|
|
$contract->segments()->attach($segment->id);
|
|
//\Log::info("Added contract to terrain", ['contract_id' => $contract->id, 'segment' => $segment->name ]);
|
|
}
|
|
}
|
|
|
|
public function failed(ContractToTerrain $event, $exception)
|
|
{
|
|
//\Log::error('Failed to update inventory', ['contract_id' => $event->contract->id, 'error' => $exception->getMessage()]);
|
|
}
|
|
}
|