I want to be able to automatically create a User every time an Employee is created. For this, in my view I have created two forms, userForm and employeeForm using the Inertia form helper.
How do I get the id of the newly created user and pass it to the employeeForm before posting it. So far I have tried Redirect::back()->with(['user'=>$user]) but I don't seem to be getting the user object in the response that is received in the onSuccess callback of the userForm.
The reason I am trying to avoid using axios or fetch is mostly academic. If there's no elegant solution then that is what I'll be doing but I'm just curious as to how others are handling this problem.
You're creating a key/value pair on the session for this response. If you want to be able to access it on your page, then the controller method that returns the page will need to access the session variable and pass it as a prop to the page.
So your controller for displaying the form would need: