-
app/Providers/AuthServiceProvider.php
Open in GitHubuse App\Models\Campaign; use App\Policies\CampaignPolicy; use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider; class AuthServiceProvider extends ServiceProvider { public function boot() { if (!app()->runningInConsole() || $this->shouldLoadPolicies()) { $this->registerPolicies(); } // } protected $policies = [ // Campaign::class => CampaignPolicy::class, // 'App\Models\Entity' => 'App\Policies\EntityPolicy', // ]; }
-
app/Policies/CampaignPolicy.php
Open in GitHubuse App\User; use App\Models\Campaign; class CampaignPolicy { // public function access(User $user, Campaign $campaign): bool { if ($campaign->isPublic()) { return true; } return $campaign->userIsMember(); } // }
-
app/Policies/EntityPolicy.php
Open in GitHubuse App\Models\Entity; use App\User; use Illuminate\Auth\Access\HandlesAuthorization; class EntityPolicy { use HandlesAuthorization; public function attributes(?User $user, Entity $entity) { if ($entity->exists === false) { return true; } return $entity->is_attributes_private ? ($user && $user->isAdmin()) : true; } // }
-
app/Http/Controllers/Api/v1/EntityInventoryApiController.php
Open in GitHubuse App\Models\Campaign; use App\Models\Entity; class EntityInventoryApiController extends ApiController { public function index(Campaign $campaign, Entity $entity) { $this->authorize('access', $campaign); $this->authorize('view', $entity->child); return Resource::collection($entity->inventories); } // }