Check Matt Stauffer's blog.
Pretty good explanation of the Middleware (and others)
https://mattstauffer.co/blog/laravel-5.0-middleware-filter-style
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!
The Laravel portal for problem solving, knowledge sharing and community building.
The community