Skip to content

Instantly share code, notes, and snippets.

@sunil-bagde
Forked from jobcerto/AuthorizesVue.php
Created June 28, 2019 18:42
Show Gist options
  • Save sunil-bagde/f2e4896ff848a5e0e01dc19d8a20b91a to your computer and use it in GitHub Desktop.
Save sunil-bagde/f2e4896ff848a5e0e01dc19d8a20b91a to your computer and use it in GitHub Desktop.
<?php
namespace App\Core\Concerns;
trait AuthorizesVue
{
/**
* Accessor for can attribute.
*/
public function getCanAttribute()
{
if ( ! auth()->check()) {
return [];
}
return [
'viewAny' => me()->can('viewAny', static::class),
'view' => me()->can('view', $this),
'create' => me()->can('create', static::class),
'update' => me()->can('update', $this),
'delete' => me()->can('delete', $this),
'restore' => me()->can('restore', $this),
'forceDelete' => me()->can('forceDelete', $this),
];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment