dimanche 13 août 2017

Laravel 5 Middleware not working properly

I have define a middleware in laravel 5. But when I login it redirect me to dashboard but dashboard doesn't show and an error occurred. I have upload a picture of it. http://ift.tt/2fC4aiV

AdminAuth.php

<?php
namespace App\Http\Middleware;
use Closure;
use Auth;
class AdminAuth 
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        if(Auth::check())
        {
            $user = Auth::user();
            return redirect()->route('admin_display_dashboard'); 
        }  else {
            return redirect()->route('admin_display_login');
        }
    }
}   

Kernel.php

<?php
namespace App\Http;
use Illuminate\Foundation\Http\Kernel as HttpKernel;
class Kernel extends HttpKernel {
    protected $middleware = [
        \Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode::class,
    ];
    protected $middlewareGroups = [
        'web' => [
            \App\Http\Middleware\EncryptCookies::class,
            \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
            \Illuminate\Session\Middleware\StartSession::class,
            \Illuminate\View\Middleware\ShareErrorsFromSession::class,
            \App\Http\Middleware\VerifyCsrfToken::class,
        ],
        'api' => [
            'throttle:60,1',
        ],
    ];
    protected $routeMiddleware = [
        'auth' => \App\Http\Middleware\Authenticate::class,
        'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
        'can' => \Illuminate\Foundation\Http\Middleware\Authorize::class,
        'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
        'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
        'adminAuth' => \App\Http\Middleware\AdminAuth::class,
    ];
}

Route.php

Route::group(['middleware' => ['adminAuth']], function () {

Route::get('admin/dashboard', array('as'=>'admin_display_dashboard', 'uses'=>'AdminViewController@displayDashboard'));

});



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire