I am new to Laravel; working on a simple CRUD app; after login i want to redirect me to another page like welcome; however I am getting bellow error; appreciate if you could help to resolve. (ErrorException Undefined index: user http://localhost:8000/user)
**controller:**
<?php>
> namespace App\Http\Controllers;
> use Illuminate\Http\Request;
> class UserAuth extends Controller
> {
> function userLogin(request $req)
> {
> $data= $req->input();
> $req->session()->put('user',$data['user']);
> return redirect('welcome');
> //echo "success";
> }
> }
**Route:**
Route::post('user', [UserAuth::class, 'userLogin']);
Route::view("login", 'login'); Route::view("welcome", 'welcome');
**Login.blade.php**
<form action="user" method="POST">
CodePudding user response:
Looks like you are trying to get user
key in $data
array when this key doesn't exist. Following the logic that i think you wanna apply, the form must have a input with name user
.
<input name="user" type="text">
CodePudding user response:
Try to return view
in your controller using
return view('welcome');