// if called like this, it will return latest status name
$latest_compliance_self_declaration_status = $latest_compliance_self_declaration->rcu_case->status;
<?php
namespace App;
use App\Traits\Filterable;
use App\Traits\ListRenderable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Spatie\ModelStatus\HasStatuses;
class RcuCase extends Model
{
use HasStatuses;
use SoftDeletes;
protected $fillable = [
'created_by',
];
protected $appends = [
'latest_status_name',
'latest_status',
];
// append latest status name to json
// return : PICKED_UP
public function getLatestStatusNameAttribute()
{
return $this->status;
}
// append latest status to json
// this will result to something like this
/*
"latest_status": {
"id": 16,
"name": "PICKED_UP",
"reason": null,
"model_id": 5,
"model_type": "App\\RcuCase",
"causer_id": 3,
"created_at": "2018-08-16 11:14:52",
"updated_at": "2018-08-16 11:14:52",
"deleted_at": null,
},
*/
public function getLatestStatusAttribute()
{
return $this->status();
}
}