43

I cant understand why I am getting the above error when I navigate to the admin login page of my Laravel project. The Laravel version is 7x. How can i fix this?

enter image description here

<?php

namespace App\Http\Controllers\Admin;

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


class LoginController extends Controller
{
    use AuthenticatesUsers;

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

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

    /**
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
     */
    public function showLoginForm()
    {
        return view('admin.auth.login');
    }
}
James Z
  • 12,209
  • 10
  • 24
  • 44
Wanjila Abraham
  • 521
  • 1
  • 7
  • 17
  • I cannot find any definitions for `AuthenticatesUsers` in Laravel API reference section. I think the trait is removed in Laravel 7.x and please let me know if you had setup the authentication using command:`composer require laravel/ui` ? – Sachin Bahukhandi May 01 '20 at 16:37
  • @SachinBahukhandi I couldn't find either, and no I did not use that command `composer require laravel/ui` while setting, how would you have handled that error? – Wanjila Abraham May 01 '20 at 18:14
  • 1
    Well I used the composer command to generate the preset for login and it's views. I would strongly recommend you to use the command rather than re inventing the wheel. – Sachin Bahukhandi May 01 '20 at 18:58
  • 1
    https://laracasts.com/discuss/channels/general-discussion/laravel-7-update-showloginform-does-not-exist please check – Sachin Bahukhandi May 02 '20 at 04:07
  • Thank you so much @SachinBahukhandi, installing `composer require laravel/ui` worked – Wanjila Abraham May 02 '20 at 15:57
  • Ok I think I should post this as an answer for any future reference. Please mark it as accepted and encourage us to help others better. :) – Sachin Bahukhandi May 02 '20 at 18:28
  • @SachinBahukhandi please check https://stackoverflow.com/questions/61625058/laravel-7x-admin-login-loops-back-to-admin-login-despite-correct-credentials – Wanjila Abraham May 07 '20 at 19:17

3 Answers3

84

Ok if anyone has this error this is because of the following:

All authentication scaffolding has been moved to the laravel/ui repository. If you are using Laravel's authentication scaffolding, you should install the ^2.0 release of this package and the package should be installed in all environments.

So to resolve the error simply run the composer command on the root folder of the laravel application:

composer require laravel/ui "^2.0"

Or simply run:

composer require laravel/ui

Hope this helps.

Sachin Bahukhandi
  • 2,378
  • 20
  • 29
  • 3
    composer require laravel/ui this command installs ui 3 that is not compatible with laravel latest 7. so it is better to install composer require laravel/ui "^2.0" – Ariful Islam Oct 13 '20 at 11:48
  • 2
    Please check the time this answer was posted. Right now we only need this if we aren't using the default vue preset. – Sachin Bahukhandi Oct 13 '20 at 11:50
  • I you stucked into version issues, check laravel version specific laravel/ui versions here:- https://stackoverflow.com/a/73822251/5783617 – Pawan Verma Sep 23 '22 at 01:54
5

In a terminal window, execute this command:

composer require laravel/ui "^2.0"

Then execute one of these commands (with your JS favorite framework):

Once the laravel/ui package has been installed, you may install the frontend scaffolding using the ui Artisan commands:

php artisan ui vue --auth

Restart your local development environment and your code editor.

Heterocigoto
  • 183
  • 2
  • 11
  • You say to execute one of these commands", but do not immediately list the choices. Please edit to add those commands, or edit to clarify what you meant. – SherylHohman Dec 22 '20 at 17:17
0

Just a small addition.

I was looking to add custom logic to login and was looking to override the attemptLogin functionality in AuthenticatesUsers trait, but could not find it under Illuminate\Foundation\Auth\AuthenticatesUsers.

Note that this is now in laravel/ui/auth-backend/ folder in vendor directory.

nwaweru
  • 1,723
  • 1
  • 13
  • 14