Laravel 5.2 - 方法身份验证不存在

时间:2018-05-02 10:12:13

标签: php laravel authentication composer-php laravel-5.2

我最近克隆了一个Laravel 5.2项目。运行composer install后,每次Artisan命令和尝试访问应用程序后,我都会收到以下错误:

  

方法身份验证不存在

我可以找到类似的"方法不存在"在线发布,但没有关于' auth'。我相信' auth'被引用的类是内置的类,可以用作各种路由的中间件。但是,我不知道如何解决这个问题。

我试过了:

  • composer dump-autoload -o
  • 删除供应商库并使用composer重新安装
  • 重置为远程分支
  • 重新克隆存储库
  • 在PHP 5.6和7.1下运行

非常感谢任何帮助!

我的作曲家档案:

{
"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"
} 
}

来自laravel.log文件的错误堆栈跟踪:

  

[2018-05-01 12:49:56] local.ERROR:BadMethodCallException:方法auth不存在。在/Applications/XAMPP/xamppfiles/htdocs/[ProjectName]/vendor/laravel/framework/src/Illuminate/Support/Traits/Macroable.php:81   堆栈跟踪:

     
      
  1. / Applications / XAMPP / xamppfiles / htdocs / [ProjectName] /vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php(213):Illuminate \ Routing \ Router-> __ call(&#39) ; auth',Array)
  2.   
  3. / Applications / XAMPP / xamppfiles / htdocs / [ProjectName] /app/Http/routes.php(424):Illuminate \ Support \ Facades \ Facade :: __ callStatic(&#39; auth&#39;,Array)< / LI>   
  4. / Applications / XAMPP / xamppfiles / htdocs / [ProjectName] /app/Providers/RouteServiceProvider.php(41):require(&#39; / Applications / X ...&#39;)
  5.   
  6. [内部功能]:App \ Providers \ RouteServiceProvider-&gt; App \ Providers {closure}(对象(Illuminate \ Routing \ Router))
  7.   
  8. / Applications / XAMPP / xamppfiles / htdocs / [ProjectName] /vendor/laravel/framework/src/Illuminate/Routing/Router.php(354):call_user_func(Object(Closure),Object(Illuminate \ Routing \ Router) )
  9.   
  10. / Applications / XAMPP / xamppfiles / htdocs / [ProjectName] /app/Providers/RouteServiceProvider.php(42):Illuminate \ Routing \ Router-&gt; group(Array,Object(Closure))
  11.   
  12. [内部功能]:App \ Providers \ RouteServiceProvider-&gt; map(对象(Illuminate \ Routing \ Router))
  13.   
  14. / Applications / XAMPP / xamppfiles / htdocs / [ProjectName] /vendor/laravel/framework/src/Illuminate/Container/Container.php(507):call_user_func_array(Array,Array)
  15.   
  16. / Applications / XAMPP / xamppfiles / htdocs / [ProjectName] /vendor/laravel/framework/src/Illuminate/Foundation/Support/Providers/RouteServiceProvider.php(72):Illuminate \ Container \ Container-&gt; call(Array) )
  17.   
  18. / Applications / XAMPP / xamppfiles / htdocs / [ProjectName] /vendor/laravel/framework/src/Illuminate/Foundation/Support/Providers/RouteServiceProvider.php(31):Illuminate \ Foundation \ Support \ Providers \ RouteServiceProvider-&gt ; loadRoutes()
  19.   
  20. / Applications / XAMPP / xamppfiles / htdocs / [ProjectName] /app/Providers/RouteServiceProvider.php(29):Illuminate \ Foundation \ Support \ Providers \ RouteServiceProvider-&gt; boot(Object(Illuminate \ Routing \ Router))
  21.   
  22. [内部功能]:App \ Providers \ RouteServiceProvider-&gt; boot(对象(Illuminate \ Routing \ Router))
  23.   
  24. / Applications / XAMPP / xamppfiles / htdocs / [ProjectName] /vendor/laravel/framework/src/Illuminate/Container/Container.php(507):call_user_func_array(Array,Array)
  25.   
  26. / Applications / XAMPP / xamppfiles / htdocs / [ProjectName] /vendor/laravel/framework/src/Illuminate/Foundation/Application.php(734):Illuminate \ Container \ Container-&gt; call(Array)
  27.   
  28. / Applications / XAMPP / xamppfiles / htdocs / [ProjectName] /vendor/laravel/framework/src/Illuminate/Foundation/Application.php(717):Illuminate \ Foundation \ Application-&gt; bootProvider(Object(App \ Providers) \ RouteServiceProvider))   15 [内部功能]:Illuminate \ Foundation \ Application-&gt; Illuminate \ Foundation {closure}(对象(App \ Providers \ RouteServiceProvider),16)
  29.   
  30. / Applications / XAMPP / xamppfiles / htdocs / [ProjectName] /vendor/laravel/framework/src/Illuminate/Foundation/Application.php(718):array_walk(Array,Object(Closure))
  31.   
  32. / Applications / XAMPP / xamppfiles / htdocs / [ProjectName] /vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/BootProviders.php(17):Illuminate \ Foundation \ Application-&gt; boot()
  33.   
  34. / Applications / XAMPP / xamppfiles / htdocs / [ProjectName] /vendor/laravel/framework/src/Illuminate/Foundation/Application.php(203):Illuminate \ Foundation \ Bootstrap \ BootProviders-&gt; bootstrap(Object(Illuminate) \基金会\应用程序))
  35.   
  36. / Applications / XAMPP / xamppfiles / htdocs / [ProjectName] /vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(208):Illuminate \ Foundation \ Application-&gt; bootstrapWith(Array)< / LI>   
  37. / Applications / XAMPP / xamppfiles / htdocs / [ProjectName] /vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(105):Illuminate \ Foundation \ Console \ Kernel-&gt; bootstrap()
  38.   
  39. / Applications / XAMPP / xamppfiles / htdocs / [ProjectName] / artisan(35):Illuminate \ Foundation \ Console \ Kernel-&gt; handle(Object(Symfony \ Component \ Console \ Input \ ArgvInput),Object(Symfony \部件\控制台\输出\ ConsoleOutput))
  40.   
  41. {主}
  42.   

3 个答案:

答案 0 :(得分:2)

使用以下路由替换Route :: auth(),或

// 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');

答案 1 :(得分:0)

感谢@JagadeshaNH我能够解决这个问题。

routes.php包含以下行: 路线:: AUTH();

这会调用一个生成一堆身份验证路由的函数。

第一次运行composer install后,它显然没有为Laravel 5.2安装所有版本更新,其中包含php artisan make:auth命令和实际的auth函数。

由于这些文件不存在,工匠仍然失败,应用程序无法运行。

解决方案是:

  1. 在routes.php文件中注释掉Route::auth()
  2. 运行composer update(由于错误,之前无效)
  3. 取消注释Route::auth()

答案 2 :(得分:0)

尝试命令

php artisan make:auth