As it's write in doc, i used Laravel's Gate::before() method.
use Illuminate\Support\Facades\Gate;
class AuthServiceProvider extends ServiceProvider
{
public function boot()
{
$this->registerPolicies();
// Implicitly grant "Super Admin" role all permissions
// This works in the app by using gate-related functions like auth()->user->can() and @can()
Gate::before(function ($user, $ability) {
return $user->hasRole('Super Admin') ? true : null;
});
}
}
But it doesn't work. I had the role in middleaware groupe in web.php and it's work. The role 'Super Admin' dont have any permission.
Route::group(['middleware' => ['auth:api','role:Super Admin|Provider']], function() {
...
}
In my ProviderController
class ProviderController extends Controller
{
function __construct(){
$this->middleware('permission:provider-list|provider-create|provider-edit|provider-delete', ['only' => ['index','show']]);
$this->middleware('permission:provider-create', ['only' => ['create','store']]);
$this->middleware('permission:provider-edit', ['only' => ['edit','update']]);
$this->middleware('permission:provider-delete', ['only' => ['destroy']]);
}
My question it's the right way or not ? I thank you in advance.