ikartik90
ikartik90

Reputation: 2815

How to display a success message upon redirection from controller in Laravel?

In my application I have a form that validates and inserts records into the table.

Upon successful insertion into the table the controller redirect()s back to the page ass follows:

return redirect('/');

This works fine, except for the fact that it doesn't tell the user of whether the insertion took place at all or not as only the blank form remains on the page while no success message is displayed.

How can I redirect along with data (some form of return code) so that I can display a simple success message?

Upvotes: 4

Views: 16537

Answers (2)

Y. Joy Ch. Singha
Y. Joy Ch. Singha

Reputation: 3252

return redirect('/')->with('success', 'Thanks for contacting us!');

and @include('flash-message') used this where you want to show your flash message on your page. thanks

Upvotes: 0

Limon Monte
Limon Monte

Reputation: 54379

return redirect('/')->with('message', 'Message sent!');

Read more about redirects in Laravel.

Be sure that Session is working properly to get flash message working.

Upvotes: 10

Related Questions