diff --git a/app/Providers/AuthServiceProvider.php b/app/Providers/AuthServiceProvider.php index ce74491..325a094 100644 --- a/app/Providers/AuthServiceProvider.php +++ b/app/Providers/AuthServiceProvider.php @@ -2,6 +2,8 @@ namespace App\Providers; +use App\Models\Channel; +use App\Models\User; use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider; use Illuminate\Support\Facades\Gate; @@ -25,6 +27,8 @@ public function boot() { $this->registerPolicies(); - // + Gate::define('show-channel', function (User $user, Channel $channel) { + return $user->id === $channel->user_id; + }); } } diff --git a/routes/web.php b/routes/web.php index 93830b1..69bc11a 100644 --- a/routes/web.php +++ b/routes/web.php @@ -46,9 +46,12 @@ ->name('channels.store'); Route::middleware(['auth:sanctum', 'verified']) ->get('/channels/{channel}', ShowingChannelController::class) + ->middleware('can:show-channel,channel') ->name('channels.show'); + Route::middleware(['auth:sanctum', 'verified']) ->post('/channels/{channel}/sync-videos', SyncVideosController::class) + ->middleware('can:show-channel,channel') ->name('channels.show.sync-videos'); Route::middleware(['auth:sanctum', 'verified'])