I created a function in users model to return permission and return as obj, but when I type:
{{ Auth::user()->permission()->outlineAgreements }}
it says:
htmlspecialchars() expects parameter 1 to be string, object given
How can I fix it ?
PS: inside test value is an array
{"outlineAgreements":["view"],"purchaseOrder":["view"],"pwra":["view","create","update","delete"]}
public function permission()
{
$permissions = auth()->user()->getAllPermissions()->pluck('name');
foreach ($permissions as $key => $value) {
$module = last(explode(" ", $value));
$action = current(explode(" ", $value));
$result[$module] = $result[$module] ?? [];
array_push($result[$module], $action);
}
return json_decode(json_encode($result));
}
last().