I have configured a resource route as below
Route::resource('users', UserController::class); When a user posts data, it will call the store method in the controller where it will add the data and set a message for success/failure.
public function store(Request $request) { // return $request; $request->validate( [ "firstName" => 'required', "lastName" => 'required', "phoneNo" => 'required', "email" => 'email:rfc,dns' ] ); $date = date(now()); $data = [ 'firstName' => $request->firstName, 'lastName' => $request->lastName, 'phoneNo' => $request->phoneNo, 'email' => $request->email, 'designation' => $request->designation, 'status' => $request->status, 'createdAt' => $date, 'updatedAt' => $date, ]; $user = Firebase::insertData($data, static::$collection); if ($user->id() != null) { $message = "User Created Successfully"; } else { $message = "Something went wrong. Please contact System Admin with error code USR001"; } return redirect()->route('users.index', ['message' => $message]); } This will redirect to the index method of the same controller. How can I use the $message parameter in the index method and send it to the view? My index method is below
public function index() { $userCollection = app('firebase.firestore')->database()->collection('users'); $userData = $userCollection->documents(); $response = []; $app = app(); foreach ($userData as $data) { $user = $app->make('stdClass'); $user->firstName = $data["firstName"]; $user->lastName = $data["lastName"]; $user->phoneNo = $data["phoneNo"]; $user->email = $data["email"]; $user->designation = $data["designation"]; $user->status = $data["status"]; $user->createdAt = $data["createdAt"]; $user->updatedAt = $data["updatedAt"]; array_push($response, $user); } return view('pages.user.list-user', ['response' => $response]); }