2026-02-06 11:26:13 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Providers;
|
|
|
|
|
|
2026-02-06 14:33:11 +02:00
|
|
|
use Illuminate\Support\Facades\Gate;
|
2026-02-06 11:26:13 +02:00
|
|
|
use Illuminate\Support\ServiceProvider;
|
|
|
|
|
|
|
|
|
|
class AppServiceProvider extends ServiceProvider
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* Register any application services.
|
|
|
|
|
*/
|
|
|
|
|
public function register(): void
|
|
|
|
|
{
|
|
|
|
|
//
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Bootstrap any application services.
|
|
|
|
|
*/
|
|
|
|
|
public function boot(): void
|
|
|
|
|
{
|
2026-02-06 14:33:11 +02:00
|
|
|
// Product-related Gates
|
|
|
|
|
Gate::define('create-product', function ($user) {
|
|
|
|
|
return $user->hasAnyRole(['user', 'moderator', 'admin']);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Gate::define('edit-product', function ($user, $product) {
|
|
|
|
|
return $user->id === $product->user_id || $user->hasAnyRole(['moderator', 'admin']);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Gate::define('delete-product', function ($user, $product) {
|
|
|
|
|
return $user->id === $product->user_id || $user->hasAnyRole(['moderator', 'admin']);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Gate::define('approve-product', function ($user) {
|
|
|
|
|
return $user->hasAnyRole(['moderator', 'admin']);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Gate::define('reject-product', function ($user) {
|
|
|
|
|
return $user->hasAnyRole(['moderator', 'admin']);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Comment-related Gates
|
|
|
|
|
Gate::define('delete-comment', function ($user, $comment) {
|
|
|
|
|
return $user->id === $comment->user_id || $user->hasAnyRole(['moderator', 'admin']);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// User management Gates
|
|
|
|
|
Gate::define('manage-users', function ($user) {
|
|
|
|
|
return $user->isAdmin();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Gate::define('manage-roles', function ($user) {
|
|
|
|
|
return $user->isAdmin();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Gate::define('manage-settings', function ($user) {
|
|
|
|
|
return $user->isAdmin();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Admin check
|
|
|
|
|
Gate::before(function ($user, $ability) {
|
|
|
|
|
if ($user->isAdmin()) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
});
|
2026-02-06 11:26:13 +02:00
|
|
|
}
|
|
|
|
|
}
|