I am redirected to the desired page but success message is supposed to be shown there but there is no message has been shown. I have tried multiple methods online but there is something I missing.
Controller File:
public function store(Request $request) { $inputs = $request->all(); // logger("I am here"); $request->validate([ 'first_name' => 'required', 'last_name' => 'required', 'email' => 'required|email|unique:users,email', 'phone_number' => 'required', 'dob' => 'required|date' ]); // dd($inputs); $user = User::create([ 'first_name' => $inputs['first_name'], 'last_name' => $inputs['last_name'], 'email' => $inputs['email'], 'phone_number' => $inputs['phone_number'], 'dob' => $inputs['dob'], 'role_id'=> 2 ]); $user->session()->flash('success', 'your account has been created.'); return redirect('/'); // dd('success validation'); }
Blade File:
@if (session()->has('success')) <div class="alert alert-success"> <p>{{ session('success') }}</p> </div> @endif
Advertisement
Answer
Try this
Session::flash('success', 'your account has been created!');
or there is another method called with() you can use it after redirect()
return redirect() ->with('success', 'your account has been created');