Turns out you cant just return a string. If you wrap the string in response() then all is fine :-)
Problem accessing query parameters in middleware
I am playing with middleware and trying to make my own. I want a middleware that returns a message "You must say the magic word" if a query parameter 'please' is not present. I think I have the right logic. It works if 'please' is present, but throws an exception is please is not present: Trying to get property 'headers' of non-object in the VerifyCsrfToken.php class where the request is having a cookie set.
My handle method is: public function handle($request, Closure $next) { $pleaseExists = $request->exists('please'); if ($pleaseExists) { return $next($request); } else { return "You must say the magic word."; } }
Any ideas? I am stumpt. I guess by accessing the parameters the request is getting corrupt in some way?
Please or to participate in this conversation.