Support the ongoing development of Laravel.io →
posted 9 years ago
Requests
Last updated 2 years ago.
0

Check Matt Stauffer's blog.

Pretty good explanation of the Middleware (and others)

https://mattstauffer.co/blog/laravel-5.0-middleware-filter-style

0

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?

0

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);
}
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Yelldon yelldon Joined 2 Mar 2015

Moderators

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

Your logo here?

Laravel.io

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

© 2024 Laravel.io - All rights reserved.