我最近克隆了一个Laravel 5.2项目。运行composer install
后,每次Artisan命令和尝试访问应用程序后,我都会收到以下错误:
方法身份验证不存在
我可以找到类似的"方法不存在"在线发布,但没有关于' auth'。我相信' auth'被引用的类是内置的类,可以用作各种路由的中间件。但是,我不知道如何解决这个问题。
我试过了:
非常感谢任何帮助!
我的作曲家档案:
{
"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 堆栈跟踪:
- / Applications / XAMPP / xamppfiles / htdocs / [ProjectName] /vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php(213):Illuminate \ Routing \ Router-> __ call(&#39) ; auth',Array)
- / Applications / XAMPP / xamppfiles / htdocs / [ProjectName] /app/Http/routes.php(424):Illuminate \ Support \ Facades \ Facade :: __ callStatic(&#39; auth&#39;,Array)< / LI>
- / Applications / XAMPP / xamppfiles / htdocs / [ProjectName] /app/Providers/RouteServiceProvider.php(41):require(&#39; / Applications / X ...&#39;)
- [内部功能]:App \ Providers \ RouteServiceProvider-&gt; App \ Providers {closure}(对象(Illuminate \ Routing \ Router))
- / Applications / XAMPP / xamppfiles / htdocs / [ProjectName] /vendor/laravel/framework/src/Illuminate/Routing/Router.php(354):call_user_func(Object(Closure),Object(Illuminate \ Routing \ Router) )
- / Applications / XAMPP / xamppfiles / htdocs / [ProjectName] /app/Providers/RouteServiceProvider.php(42):Illuminate \ Routing \ Router-&gt; group(Array,Object(Closure))
- [内部功能]:App \ Providers \ RouteServiceProvider-&gt; map(对象(Illuminate \ Routing \ Router))
- / Applications / XAMPP / xamppfiles / htdocs / [ProjectName] /vendor/laravel/framework/src/Illuminate/Container/Container.php(507):call_user_func_array(Array,Array)
- / Applications / XAMPP / xamppfiles / htdocs / [ProjectName] /vendor/laravel/framework/src/Illuminate/Foundation/Support/Providers/RouteServiceProvider.php(72):Illuminate \ Container \ Container-&gt; call(Array) )
- / Applications / XAMPP / xamppfiles / htdocs / [ProjectName] /vendor/laravel/framework/src/Illuminate/Foundation/Support/Providers/RouteServiceProvider.php(31):Illuminate \ Foundation \ Support \ Providers \ RouteServiceProvider-&gt ; loadRoutes()
- / Applications / XAMPP / xamppfiles / htdocs / [ProjectName] /app/Providers/RouteServiceProvider.php(29):Illuminate \ Foundation \ Support \ Providers \ RouteServiceProvider-&gt; boot(Object(Illuminate \ Routing \ Router))
- [内部功能]:App \ Providers \ RouteServiceProvider-&gt; boot(对象(Illuminate \ Routing \ Router))
- / Applications / XAMPP / xamppfiles / htdocs / [ProjectName] /vendor/laravel/framework/src/Illuminate/Container/Container.php(507):call_user_func_array(Array,Array)
- / Applications / XAMPP / xamppfiles / htdocs / [ProjectName] /vendor/laravel/framework/src/Illuminate/Foundation/Application.php(734):Illuminate \ Container \ Container-&gt; call(Array)
- / 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)
- / Applications / XAMPP / xamppfiles / htdocs / [ProjectName] /vendor/laravel/framework/src/Illuminate/Foundation/Application.php(718):array_walk(Array,Object(Closure))
- / Applications / XAMPP / xamppfiles / htdocs / [ProjectName] /vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/BootProviders.php(17):Illuminate \ Foundation \ Application-&gt; boot()
- / Applications / XAMPP / xamppfiles / htdocs / [ProjectName] /vendor/laravel/framework/src/Illuminate/Foundation/Application.php(203):Illuminate \ Foundation \ Bootstrap \ BootProviders-&gt; bootstrap(Object(Illuminate) \基金会\应用程序))
- / Applications / XAMPP / xamppfiles / htdocs / [ProjectName] /vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(208):Illuminate \ Foundation \ Application-&gt; bootstrapWith(Array)< / LI>
- / Applications / XAMPP / xamppfiles / htdocs / [ProjectName] /vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(105):Illuminate \ Foundation \ Console \ Kernel-&gt; bootstrap()
- / Applications / XAMPP / xamppfiles / htdocs / [ProjectName] / artisan(35):Illuminate \ Foundation \ Console \ Kernel-&gt; handle(Object(Symfony \ Component \ Console \ Input \ ArgvInput),Object(Symfony \部件\控制台\输出\ ConsoleOutput))
- {主}
醇>
答案 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
函数。
由于这些文件不存在,工匠仍然失败,应用程序无法运行。
解决方案是:
Route::auth()
composer update
(由于错误,之前无效)Route::auth()
答案 2 :(得分:0)
尝试命令
php artisan make:auth