File: /var/www/ipsremont-demo/app/Models/ShipmentChanges.php
<?php
namespace App\Models;
use App\Services\Status\StatusService;
use App\Traits\My;
use App\User;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Support\Facades\Auth;
/**
* @property int $id
* @property int $shipment_id
* @property string $status
* @property string $created_at
* @property string $updated_at
* @property string $deleted_at
* @property int $user_id
*/
class ShipmentChanges extends BaseModel
{
use SoftDeletes, My;
protected $_status = null;
protected $fillable = [
'shipment_id',
'status',
];
public function user()
{
return $this->belongsTo(User::class);
}
public function status()
{
if (!$this->_status) {
$this->_status = StatusService::getShipmentBySlug($this->status);
}
return $this->_status;
}
/**
* @param int $shipmentId
* @param string $status
*
* @return void
*/
public function _save($shipmentId, $status): void
{
$this->shipment_id = $shipmentId;
$this->status = $status;
$this->user_id = Auth::id() ?? 0;
$this->save();
}
}