I think that example can be shorter too!
function canView($scope, $ownerId) {
return ($scope === 'public' ||
Auth::user()->hasRole('admin') ||
($scope === 'private' && Auth::user()->id === $ownerId));
}
I build things with my hands. The human behind Shift - https://laravelshift.com, master of Git - https://gettinggit.com, and author of "BaseCode" - https://basecodefieldguide.com
I think that example can be shorter too!
function canView($scope, $ownerId) {
return ($scope === 'public' ||
Auth::user()->hasRole('admin') ||
($scope === 'private' && Auth::user()->id === $ownerId));
}
As noted in other comments, it's not about shorter, it's about more readable.