dimanche 27 décembre 2015

Middleware not working as expected - Laravel

This is driving me crazy as I think I'm doing the right thing but its not working correctly.

I have a route with a middleware attached to it like below;

Route::get('post/{id}/{name}', 'BlogController@post')->name('blog-post')->middleware('blogGuard');

As you can see I've defined 2 route params In my controller I have below;

public function post () {
    return view('pages.blog.post');
}

With the middleware defined like this;

public function handle($request, Closure $next)
{

    if (is_null($request->input('id')) ||
        is_null($request->input('name'))) {

        return redirect()->route('blog-home');
    }

    return $next($request);
}

Now if I click on a link like so; http://ift.tt/1mkRpr0 the middleware should not fire correct?

This is not the case. The middleware executes and I'm redirected. But if I remove the middleware then I'm able to access the page.

Any help appreciated.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire