2017-06-15 20:54:14 -07:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Observers;
|
|
|
|
|
|
|
|
use App\Models\Accessory;
|
|
|
|
use App\Models\Actionlog;
|
2024-05-29 04:38:15 -07:00
|
|
|
use Illuminate\Support\Facades\Auth;
|
2017-06-15 20:54:14 -07:00
|
|
|
|
|
|
|
class AccessoryObserver
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Listen to the User created event.
|
|
|
|
*
|
|
|
|
* @param Accessory $accessory
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function updated(Accessory $accessory)
|
|
|
|
{
|
|
|
|
$logAction = new Actionlog();
|
|
|
|
$logAction->item_type = Accessory::class;
|
|
|
|
$logAction->item_id = $accessory->id;
|
2021-06-10 13:15:52 -07:00
|
|
|
$logAction->created_at = date('Y-m-d H:i:s');
|
2017-06-20 20:38:13 -07:00
|
|
|
$logAction->user_id = Auth::id();
|
2017-06-15 20:54:14 -07:00
|
|
|
$logAction->logaction('update');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-08-23 13:59:59 -07:00
|
|
|
* Listen to the Accessory created event when
|
2017-06-15 20:54:14 -07:00
|
|
|
* a new accessory is created.
|
|
|
|
*
|
|
|
|
* @param Accessory $accessory
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function created(Accessory $accessory)
|
|
|
|
{
|
|
|
|
$logAction = new Actionlog();
|
|
|
|
$logAction->item_type = Accessory::class;
|
|
|
|
$logAction->item_id = $accessory->id;
|
2021-06-10 13:15:52 -07:00
|
|
|
$logAction->created_at = date('Y-m-d H:i:s');
|
2017-06-20 20:38:13 -07:00
|
|
|
$logAction->user_id = Auth::id();
|
2024-01-25 17:54:53 -08:00
|
|
|
if($accessory->imported) {
|
2024-01-30 13:14:59 -08:00
|
|
|
$logAction->setActionSource('importer');
|
2024-01-25 17:54:53 -08:00
|
|
|
}
|
2017-06-15 20:54:14 -07:00
|
|
|
$logAction->logaction('create');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Listen to the Accessory deleting event.
|
|
|
|
*
|
|
|
|
* @param Accessory $accessory
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function deleting(Accessory $accessory)
|
|
|
|
{
|
|
|
|
$logAction = new Actionlog();
|
|
|
|
$logAction->item_type = Accessory::class;
|
|
|
|
$logAction->item_id = $accessory->id;
|
2021-06-10 13:15:52 -07:00
|
|
|
$logAction->created_at = date('Y-m-d H:i:s');
|
2017-06-20 20:38:13 -07:00
|
|
|
$logAction->user_id = Auth::id();
|
2017-06-15 20:54:14 -07:00
|
|
|
$logAction->logaction('delete');
|
|
|
|
}
|
|
|
|
}
|