Created
November 22, 2018 08:07
-
-
Save mathieutu/d742046ca00fad76c78fc3a6334ddadc to your computer and use it in GitHub Desktop.
Nova policies
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| namespace App\Policies; | |
| class AllowAllForNova | |
| { | |
| public function viewAny() | |
| { | |
| return $this->sameForAll(); | |
| } | |
| public function sameForAll() | |
| { | |
| return true; | |
| } | |
| public function view() | |
| { | |
| return $this->sameForAll(); | |
| } | |
| public function create() | |
| { | |
| return $this->sameForAll(); | |
| } | |
| public function update() | |
| { | |
| return $this->sameForAll(); | |
| } | |
| public function delete() | |
| { | |
| return $this->sameForAll(); | |
| } | |
| public function restore() | |
| { | |
| return $this->sameForAll(); | |
| } | |
| public function forceDelete() | |
| { | |
| return $this->sameForAll(); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| namespace App\Providers; | |
| use App\Models\Order; | |
| use App\Policies\AllowAllForNova; | |
| use App\Policies\OrderPolicy; | |
| use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider; | |
| use Illuminate\Support\Facades\Gate; | |
| use Laravel\Nova\Nova; | |
| class AuthServiceProvider extends ServiceProvider | |
| { | |
| protected $policies = [ | |
| Order::class => OrderPolicy::class, | |
| ]; | |
| protected $novaPolicies = [ | |
| ]; | |
| /** | |
| * Register any authentication / authorization services. | |
| * | |
| * @return void | |
| */ | |
| public function boot() | |
| { | |
| $this->registerPolicies(); | |
| Nova::serving(function() { | |
| $this->registerNovaPolicies(); | |
| }); | |
| } | |
| private function novaPolicies() | |
| { | |
| return collect($this->policies())->map(function () { | |
| return AllowAllForNova::class; | |
| })->merge($this->novaPolicies); | |
| } | |
| public function registerNovaPolicies() | |
| { | |
| foreach ($this->novaPolicies() as $key => $value) { | |
| Gate::policy($key, $value); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
tip: in
\App\Nova\Resources\Resource