I'm working on an Application with Laravel, vue.js (Inertia). There is a login page when the user enter the credentials and if he is authenticated then he should be redirected to the "Welcome.vue" and i want to pass username with it.
I have a login component that is accessible at "http://127.0.0.1:8000/Login" when the user fills out the form and hit the "login" now button following controller code is executed (which is working fine).
public function login(Request $request)
{
$credentials = $request->only('email', 'password');
if (Auth::attempt($credentials)) {
$username =Auth::user();
return Inertia('Welcome', [
'username' => $username
]);
} else {
return back()->with('message','Authenticaiton Failed');
}
}
Now I can receive it as a propos. But the problem with this method is that the page URL remain the same which is "http://127.0.0.1:8000/Login" I want to change it to "http://127.0.0.1:8000/Welcome". I can use the return redirect('Welcome')->with('username',$username); but I can't receive it as a prop. I don't know what's the exact issue.
Following is the additional code that you might need:
Route::get('/Welcome', function () {
return inertia('Welcome');
})->name('Welcome')->middleware('auth', 'AuthenticateCustom');
Route::get('/Login', function () { return inertia('Login'); })->name('Login');
Route::post('/Login', [UserController::class, 'login'])->name('login');`