简体   繁体   中英

Laravel login redirects back to login page

I'm a beginner to Laravel 5.5.* and I'm trying to create a login page.
whenever i click the login button i'm redirected back to the login form.

Here are my steps:

  1. php artisan make:auth
  2. php artisan make:migration table_name_here
  3. I modified the migration
  4. php artisan migrate

Here is my LoginController

<?php

namespace App\Http\Controllers\Auth;

use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
use Illuminate\Http\Request;
use Auth;

class LoginController extends Controller
{
    /*
    |--------------------------------------------------------------------------
    | Login Controller
    |--------------------------------------------------------------------------
    |
    | This controller handles authenticating users for the application and
    | redirecting them to your home screen. The controller uses a trait
    | to conveniently provide its functionality to your applications.
    |
    */

    use AuthenticatesUsers;

    /**
     * Where to redirect users after login.
     *
     * @var string
     */
    protected $redirectTo = '/home';

    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->middleware('guest')->except('logout');
    }

}

Here is my User Model

<?php

namespace App;

use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable
{
    use Notifiable;

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'firstname', 'lastname', 'email', 'password', 'department', 'phone', 'status', 'roleId',
    ];

    /**
     * The attributes that should be hidden for arrays.
     *
     * @var array
     */
    protected $hidden = [
        'password', 'remember_token',
    ];
}

My web.php

<?php

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/

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


Auth::routes();

Route::get('/home', 'HomeController@index')->name('home');

My table columns

staffId, roleId, firstname, lastname, username, email, department, phone, status, remember_token, created_at, updated_at, password,

只需重新启动apache服务器,然后再次运行php artisan serve命令,这可能会帮助您解决问题。

I had the same problem that the login redirected to the login page without any errors.

For me I didn't had any name tag in my input field of my form eg So it didn't know what data to send the in the request

<input type="email">
<input type="password">

Should be

<input type="email" name="email">
<input type="password" name="password">

因此,当我在本地开发环境中的session.php中设置SESSION_DOMAIN'NULL'时,我能够解决此问题。

I got the same issue having SESSION_SECURE_COOKIE=true set while migrating from an old to a new production server to a new one. HTTPS was not set up set.

By removing SESSION_SECURE_COOKIE=true , logging in started working again.

Of course, set up HTTPS and add the env var back before actually migrating servers for real.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM