I'm working in laravel btw.
In a controller, I have some logic in a try/catch. The logic is for looking up users by ID. If a bad ID is searched, I want to catch and refresh the page with an error message like "That user ID does not exist".
I'm aware of three methods that I can use which are: back()
, Redirect::to('users')
, and redirect()->route('users')
.
Firstly, which should I use?
Secondly, I've tried each and I get error messages or not the behavior I want.
Error Messages for Each
back()
I don't see anything. I redirect to the same page just fine. But the data I pass using back()->withInput(['error' => $error])
doesn't show up on the page. I have {{isset($error) ? $error : ''}}
in my template waiting for an $error variable to be set. Is there a different way to do this? Better way?
redirect()->to('users')
This acts similarly to back() in that it will redirect me just fine but still I can't seem to pass data to the page.
redirect()->route('users')
This acts similarly to back() in that it will redirect me just fine but still I can't seem to pass data to the page.
I imagine this is a simple problem. I'm just new to php and laravel and could use a little direction.
THANKS!