I want to authenticate view file for particular users. I have created middleware for this. Below is the code for middleware:-
namespace App\Http\Middleware;
use Closure;
use Illuminate\Support\Facades\Auth;
class ClientAuth
{
public function handle($request, Closure $next)
{
if(Auth::user() && Auth::user()->account_type==3)
{
return $next($request);
}
return redirect('/');
}
}
Next, I have called 'client' middleware in kernel.php file. Below is the code:-
protected $routeMiddleware = [
'auth' => \Illuminate\Auth\Middleware\Authenticate::class,
'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
'bindings' => \Illuminate\Routing\Middleware\SubstituteBindings::class,
'can' => \Illuminate\Auth\Middleware\Authorize::class,
'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
'admin' => \App\Http\Middleware\isAdmin::class,
'client' => \App\Http\Middleware\ClientAuth::class
];
Then, i have called this in route.
Route::group(['middleware' => ['auth','client']], function ()
{
Route::get('clientdatabase',
'ClientDatabase\ClientdatabaseController@ClientDatabase');
});
This is not working. Where am i going wrong?
答案 0 :(得分:-1)
your called is wrong in route. for example
Route::middleware(['auth','client'])->group(function () {
Route::get('clientdatabase','ClientDatabase\ClientdatabaseController@ClientDatabase');
});