1
votes

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,

4
That public function showLoginForm() is not part of the default LoginControllerbrombeer
just removed public function showLoginForm()from the LoginController, it didn't workChrstopher
What are you trying to log in with; username and password / email and password?Option
I'm using email.Chrstopher
I'm using email.Chrstopher

4 Answers

0
votes

Just restart apache server and again run php artisan serve command may this will help you to short out the issue.

0
votes

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 e.g. 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">
0
votes

So I am able to solve this problem, when I set the SESSION_DOMAIN 'NULL' in session.php in local development environment.

0
votes

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.