I'm using Inertia (Vue3 & Laravel 9). I have a form in "Register.vue" Component.
On submitting that form I'm calling a controller to process the request. Once the controller process the request I want the controller to redirect to an other component i.e. regComplete (where I want to show data which I received as a prop from controller).
Now the thing is the Controller is redirecting me to the desired page (Although I'm unable to get the prop data but I'm getting the other data successfully) but the URL is still same as it was on form submit.
"Register.vue"
<template>
<form @submit.prevent="submit">Here are the form fields i.e. email & password </form>
</template>
<script setup>
let form = reactive({
email: "",
password: "",
});
let submit = () =>{
Inertia.post('users',form);
}
</script>
Route.php //Route on submitting the form
Route::post('users',[userController::class,'register']);
Controller = userController
public function register(Request $request){
// $email = $request->input('email');
// $password = $request->input('password');
// return "User with".$email." and with password ".$password." is created";
return Inertia::render('regComplete');}
Now my question is How to redirect to the settings page with desired props ?
for example return Inertia::render('regComplete',['msg'=>'User registerd']);
CodePudding user response:
After successfully creating a new user, you return the Component rather than returning or redirecting to another route where the component (regComplete) is being loaded. What you can do is add more routes that deal with the (regComplete) component.
On routes.php, add the new route /registration/complete
Route::post('users',[UserController::class,'register']);
Route::get('/registration/complete',[UserController::class,'regComplete']);
On UserController.php, add new function regComplete() and update register
// add the this function
public function regComplete () {
return Inertia::render('regComplete',[
'users' => User::all() // make sure you have defineProps()
]);
}
// update your register function
public function register(Request $request){
// creation of user process here
if(successfully created) {
return redirect('/registration/complete');
}
return back()->with('error','You error message here');
}
It is possible that it will not solve your problem. However, hopefully it will assist you in determining where the problem may be occurring.