You question makes me think a while.
From the technical point of view, in a middleware you have to return an HttpResponse, and the view() helper does (so it is fine).
But I think that the problem is... when you have an HTML request you are not calling the $next() closure, so the other middlewares are not being executed (if has more). In the other hand I really can't imagine a different way to do what you want if it is not in every controller, checking if is HTML or JSON.
In conclusion, I think that you are doing wll, just be sure that your middleware is executed at the last of all.
Hope it helps :P
In the other hand I really can't imagine a different way to do what you want if it is not in every controller, checking if is HTML or JSON.
Instead of returning a view, I'd redirect to another Controller which returns view.
In Laravel 5, you'll need to wrap this in a Illuminate\Http\Response. So something like this:
in the header of your file and in your handler
return new Response(view('view.path'));
Otherwise it won't work.
Sign in to participate in this thread!
We'd like to thank these amazing companies for supporting us