\Auth::user()->can() generated in Models has no null check
coolsam726 opened this issue · 0 comments
coolsam726 commented
The getCanAttribute() function in generated model should have an Auth::check() in order to still be able to use the model when no user is logged in. Currently it throws errors
Example fix:
public function getCanAttribute() {
return [
"view" => \Auth::check() ? \Auth::user()->can("view", $this) : false,
"update" => \Auth::check() ? \Auth::user()->can("update", $this) : false,
"delete" => \Auth::check() ? \Auth::user()->can("delete", $this) : false,
"restore" => \Auth::check() ? \Auth::user()->can("restore", $this) : false,
"forceDelete" => \Auth::check() ? \Auth::user()->can("forceDelete", $this) : false,
];
}