Support the ongoing development of →
posted 9 years ago
Last updated 2 years ago.

Check Matt Stauffer's blog.

Pretty good explanation of the Middleware (and others)


I've actually read most everything that I can find doing a search, including that resource. But I'm still having trouble wrapping my head around it.

For instance, the example that I added, I can't figure out how to get it to see if published is either 1 or 0 to do a redirect based on the page ID you're looking at and whether it's published. How can I grab that property in the middleware?


Just in case anyone ever runs across this thread and needs to do something similar, here is what I ended up doing. First thing, I ended up injecting my model into the middleware, and then called it $post. Then I did this:

public function handle($request, Closure $next)
        $id = $request->route()->getParameter('id');
        $published = $this->post->find($id)->getAttribute('published');

        if ($published == 0)
            return response()->view('errors.404', [], 404);

    return $next($request);

Sign in to participate in this thread!


Your banner here too?

Yelldon yelldon Joined 2 Mar 2015


We'd like to thank these amazing companies for supporting us

Your logo here?

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 - All rights reserved.