-
app/Policies/ServerPolicy.php
Open in GitHubuse App\Models\Server; use App\Models\User; class ServerPolicy { public function viewAny(User $user): bool { return true; } public function view(User $user, Server $server): bool { return $user->currentTeam->id === $server->team_id && ! $server->uninstallation_requested_at; } public function manage(User $user, Server $server): bool { return $user->currentTeam->id === $server->team_id && ! $server->uninstallation_requested_at; } public function create(User $user): bool { return true; } public function update(User $user, Server $server): bool { return $user->currentTeam->id === $server->team_id && ! $server->uninstallation_requested_at; } public function delete(User $user, Server $server): bool { return $user->currentTeam->id === $server->team_id && ! $server->uninstallation_requested_at; } }
-
app/Providers/AuthServiceProvider.php
Open in GitHubuse App\Models; use App\Policies; use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider; class AuthServiceProvider extends ServiceProvider { protected $policies = [ // ... Models\Server::class => Policies\ServerPolicy::class, // ... ]; // ... }
-
app/Http/Controllers/ServerController.php
Open in GitHubuse App\Models\Server; class ServerController extends Controller { public function __construct() { $this->authorizeResource(Server::class, 'server'); } // ... }