Home > OS >  Laravel Login post method redirects to gives blank page
Laravel Login post method redirects to gives blank page

Time:01-18


The output should display the token on /login . But as soon I click the login button, I am directed to a blank page.


There are similar questions asked but I still wasn't able to solve. Please if anyone could help me with it.

UserController.php

<?php

namespace App\Http\Controllers;

use Illuminate\Support\Facades\Hash;
use Illuminate\Http\Request;
use App\Models\User;
class UserController extends Controller
{
    
    function login(Request $req)
    {
        return $req->input;
    }
}

web.php

<?php

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\UserController;

Route::get('/login', function () {
    return view('login');
});

Route::post("/login",[UserController::class,'login']);

The name, email and password records are visible in the database.

Model - User.php

class User extends Authenticatable
{
    use HasApiTokens, HasFactory, Notifiable;

    protected $fillable = [
        'name',
        'email',
        'password',
    ];

    protected $hidden = [
        'remember_token',
    ];

    protected $casts = [
        'email_verified_at' => 'datetime',
    ];
}

Login page

            <form action="login" method="POST">
                <div >
                    @csrf
                    <label for="exampleInputEmail1" >Email address</label>
                    <input type="email" name="email"  id="exampleInputEmail1" aria-describedby="emailHelp">
                </div>
                <div >
                    <label for="exampleInputPassword1" >Password</label>
                    <input type="password" name="password"  id="exampleInputPassword1">
                </div>

                <button type="submit" >Login</button>
            </form>

CodePudding user response:

Check action attribute in form tag.

It seems to be correct to use /login instead of login.

  •  Tags:  
  • Related