Search code examples
laravellaravel-8laravel-routing

Laravel 8 Redirection to specific page issue


I am new to Laravel; working on a simple CRUD app; after login, I want to redirect myself to another page like welcome; however, I am getting the below error; appreciate it if you could help to resolve it. (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">

Solution

  • 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">