Is it safe to remove an authentication middleware from a controller if I have already set a Gate on Laravel?
I did so:
No AuthServiceProvider.php
Gate::define( 'admin', function ( $user ) {
return $user->cargo_id == '3';
} );
On the route
Route::middleware( 'can:admin' )->prefix( 'admin' )->group( function() {
Route::get( '/', function() {
return view( 'admin.home' );
} );
In the controller I had:
public function __construct()
{
$this->middleware( 'auth' );
}
When the user accesses the page, instead of redirecting to the login, removing the middleware from the controller returns a permission error directly. I prefer that, but is this correct in terms of security?