I'm using Laravel auditing in my project and I need to be able to show the model 'name' field on the view. I get the models like so
$audit = \OwenIt\Auditing\Models\Audit::find($id);
$type = $audit->auditable_type;
$model = $type::where('id',$audit->auditable_id)->get();
and I can loop over the selected model like so
foreach ($model[0] as $key => $val) {
if (str_contains($key,'name')) {
$mname = $key;
$mval = $val;
}
}
the models have various keys identifying the name eg: the User model has 'name', the Organisation model has organisation_name
I want to get the first key and value from each model that contains the string 'name', but using the method above or strpos throws an error saying $mname is not defined. Where am I going wrong?