Skip to content

Commit

Permalink
Enhance authorization for users to show channel
Browse files Browse the repository at this point in the history
  • Loading branch information
AhmedHelalAhmed committed Sep 4, 2021
1 parent e8b0e8c commit 442a386
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
6 changes: 5 additions & 1 deletion app/Providers/AuthServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -25,6 +27,8 @@ public function boot()
{
$this->registerPolicies();

//
Gate::define('show-channel', function (User $user, Channel $channel) {
return $user->id === $channel->user_id;
});
}
}
3 changes: 3 additions & 0 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'])
Expand Down

0 comments on commit 442a386

Please sign in to comment.