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
JuanDMeGon said:
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:
use Illuminate\Http\Response;
in the header of your file and in your handler
return new Response(view('view.path'));
Otherwise it won't work.
jayakt97 liked this reply
It's work for me:
return response(view('view.path'));
jayakt97 liked this reply
Yeah
return response(view('view.path'));
Works totally for me ! Thanks !
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community