3
votes

I recently cloned a Laravel 5.2 project. After running composer install, I keep getting the following error after every Artisan command and when trying to access the app:

Method auth does not exist

I could find similar "method does not exist" issues online, but nothing about 'auth'. I believe the 'auth' class being referred to is the built-in one that can be used as middleware for various routes. However, I have no idea how to solve the issue.

I've tried:

  • composer dump-autoload -o
  • deleting the vendor libraries and reinstalling with composer
  • resetting to the remote branch
  • re-cloning the repository
  • running under PHP 5.6 and 7.1

Any help would be greatly appreciated!

My composer file:

{
"name": "laravel/laravel",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"license": "MIT",
"type": "project",
"require": {
    "php": ">=5.5.9",
    "laravel/framework": "5.2.*",
    "gloudemans/calendar": "dev-master",
    "zizaco/entrust": "5.2.x-dev",
    "laravelcollective/html": "5.2.*",
    "guzzlehttp/guzzle": "~6.0",
    "predis/predis": "~1.0",
    "aws/aws-sdk-php": "~3.0",
    "mpociot/laravel-apidoc-generator": "^2.0"
},
"require-dev": {
    "fzaninotto/faker": "~1.4",
    "mockery/mockery": "0.9.*",
    "phpunit/phpunit": "~4.0",
    "phpspec/phpspec": "~2.1",
    "symfony/dom-crawler": "~3.0",
    "symfony/css-selector": "~3.0"
},
"autoload": {
    "classmap": [
        "database"
    ],
    "psr-4": {
        "App\\": "app/"
    }
},
"autoload-dev": {
    "classmap": [
        "tests/TestCase.php"
    ]
},
"scripts": {

    "pre-update-cmd": [
        "php artisan clear-compiled"
    ],
    "post-update-cmd": [
        "php artisan optimize"
    ],
    "post-root-package-install": [
        "php -r \"copy('.env.example', '.env');\""
    ],
    "post-create-project-cmd": [
        "php artisan key:generate"
    ]
},
"config": {
    "preferred-install": "dist"
} 
}

The error's stack trace from the laravel.log file:

[2018-05-01 12:49:56] local.ERROR: BadMethodCallException: Method auth does not exist. in /Applications/XAMPP/xamppfiles/htdocs/[ProjectName]/vendor/laravel/framework/src/Illuminate/Support/Traits/Macroable.php:81 Stack trace:

  1. /Applications/XAMPP/xamppfiles/htdocs/[ProjectName]/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php(213): Illuminate\Routing\Router->__call('auth', Array)
  2. /Applications/XAMPP/xamppfiles/htdocs/[ProjectName]/app/Http/routes.php(424): Illuminate\Support\Facades\Facade::__callStatic('auth', Array)
  3. /Applications/XAMPP/xamppfiles/htdocs/[ProjectName]/app/Providers/RouteServiceProvider.php(41): require('/Applications/X...')
  4. [internal function]: App\Providers\RouteServiceProvider->App\Providers{closure}(Object(Illuminate\Routing\Router))
  5. /Applications/XAMPP/xamppfiles/htdocs/[ProjectName]/vendor/laravel/framework/src/Illuminate/Routing/Router.php(354): call_user_func(Object(Closure), Object(Illuminate\Routing\Router))
  6. /Applications/XAMPP/xamppfiles/htdocs/[ProjectName]/app/Providers/RouteServiceProvider.php(42): Illuminate\Routing\Router->group(Array, Object(Closure))
  7. [internal function]: App\Providers\RouteServiceProvider->map(Object(Illuminate\Routing\Router))
  8. /Applications/XAMPP/xamppfiles/htdocs/[ProjectName]/vendor/laravel/framework/src/Illuminate/Container/Container.php(507): call_user_func_array(Array, Array)
  9. /Applications/XAMPP/xamppfiles/htdocs/[ProjectName]/vendor/laravel/framework/src/Illuminate/Foundation/Support/Providers/RouteServiceProvider.php(72): Illuminate\Container\Container->call(Array)
  10. /Applications/XAMPP/xamppfiles/htdocs/[ProjectName]/vendor/laravel/framework/src/Illuminate/Foundation/Support/Providers/RouteServiceProvider.php(31): Illuminate\Foundation\Support\Providers\RouteServiceProvider->loadRoutes()
  11. /Applications/XAMPP/xamppfiles/htdocs/[ProjectName]/app/Providers/RouteServiceProvider.php(29): Illuminate\Foundation\Support\Providers\RouteServiceProvider->boot(Object(Illuminate\Routing\Router))
  12. [internal function]: App\Providers\RouteServiceProvider->boot(Object(Illuminate\Routing\Router))
  13. /Applications/XAMPP/xamppfiles/htdocs/[ProjectName]/vendor/laravel/framework/src/Illuminate/Container/Container.php(507): call_user_func_array(Array, Array)
  14. /Applications/XAMPP/xamppfiles/htdocs/[ProjectName]/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(734): Illuminate\Container\Container->call(Array)
  15. /Applications/XAMPP/xamppfiles/htdocs/[ProjectName]/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(717): Illuminate\Foundation\Application->bootProvider(Object(App\Providers\RouteServiceProvider)) 15 [internal function]: Illuminate\Foundation\Application->Illuminate\Foundation{closure}(Object(App\Providers\RouteServiceProvider), 16)
  16. /Applications/XAMPP/xamppfiles/htdocs/[ProjectName]/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(718): array_walk(Array, Object(Closure))
  17. /Applications/XAMPP/xamppfiles/htdocs/[ProjectName]/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/BootProviders.php(17): Illuminate\Foundation\Application->boot()
  18. /Applications/XAMPP/xamppfiles/htdocs/[ProjectName]/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(203): Illuminate\Foundation\Bootstrap\BootProviders->bootstrap(Object(Illuminate\Foundation\Application))
  19. /Applications/XAMPP/xamppfiles/htdocs/[ProjectName]/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(208): Illuminate\Foundation\Application->bootstrapWith(Array)
  20. /Applications/XAMPP/xamppfiles/htdocs/[ProjectName]/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(105): Illuminate\Foundation\Console\Kernel->bootstrap()
  21. /Applications/XAMPP/xamppfiles/htdocs/[ProjectName]/artisan(35): Illuminate\Foundation\Console\Kernel->handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
  22. {main}
3
can you post your routes here? or those routes which are using middle ware auth - Jagadesha NH
@prakashtank - I checked the link, doesn't seem to help. - M Polak
@JagadeshaNH there are quite a few routes that use that, so it would be impractical to post them all here (I might create a gist for it). However, I did notice the following route in the routes.php file: > Route::auth(); When I remove it I can now use Artisan again and the 'Method auth does not exist' error goes away. Instead, I get a different error. I'll check it and see if I can resolve it. - M Polak
app/Http/routes.php(424) can you post whats there in line 424 of your routes.php - Jagadesha NH

3 Answers

2
votes

Replace Route::auth() with the following routes, or

// Authentication Routes...
    $this->get('login', 'Auth\LoginController@showLoginForm')->name('login');
    $this->post('login', 'Auth\LoginController@login');
    $this->post('logout', 'Auth\LoginController@logout')->name('logout');

    // Registration Routes...
    $this->get('register', 'Auth\RegisterController@showRegistrationForm')->name('register');
    $this->post('register', 'Auth\RegisterController@register');

    // Password Reset Routes...
    $this->get('password/reset', 'Auth\ForgotPasswordController@showLinkRequestForm');
    $this->post('password/email', 'Auth\ForgotPasswordController@sendResetLinkEmail');
    $this->get('password/reset/{token}', 'Auth\ResetPasswordController@showResetForm');
    $this->post('password/reset', 'Auth\ResetPasswordController@reset');
0
votes

Thanks to @JagadeshaNH I was able to resolve the issue.

The routes.php contained the following line: Route::auth();

This calls to a function that generates a bunch of authentication routes.

After running composer install for the first time it apparently did not install all the version updates for Laravel 5.2, which contain the php artisan make:auth command and the actual auth function.

Because these files did not exist, artisan kept failing and the app wouldn't run.

The solution was:

  1. Comment out Route::auth() in the routes.php file
  2. Run composer update (which did not work before because of the error)
  3. Uncomment Route::auth()
-1
votes

try command

php artisan make:auth