Laravel验证唯一规则反射类异常

时间:2019-04-30 19:09:18

标签: php laravel

我正在尝试为电子邮件地址字段设置唯一规则,并且由于验证表名称被强制转换为类,因此我遇到了ReflectionException。查看文档,这应该只是将其投射到表上。

Laravel版本是:5.7。

验证规则如下:

$this->validate($request, [
    'email' => 'unique:users',
    'password' => 'same:password_confirmation'
]);

在$ this是控制器的地方,我也尝试过使用Illuminate \ Http \ Request;结果相同。

我得到的堆栈跟踪如下:

ReflectionException thrown with message "Class users does not exist"

Stacktrace:
#65 ReflectionException in /var/www/vendor/laravel-doctrine/orm/src/IlluminateRegistry.php:362
#64 ReflectionClass:__construct in /var/www/vendor/laravel-doctrine/orm/src/IlluminateRegistry.php:362
#63 LaravelDoctrine\ORM\IlluminateRegistry:getManagerForClass in /var/www/vendor/laravel-doctrine/orm/src/Validation/DoctrinePresenceVerifier.php:137
#62 LaravelDoctrine\ORM\Validation\DoctrinePresenceVerifier:getEntityManager in /var/www/vendor/laravel-doctrine/orm/src/Validation/DoctrinePresenceVerifier.php:93
#61 LaravelDoctrine\ORM\Validation\DoctrinePresenceVerifier:select in /var/www/vendor/laravel-doctrine/orm/src/Validation/DoctrinePresenceVerifier.php:46
#60 LaravelDoctrine\ORM\Validation\DoctrinePresenceVerifier:getCount in /var/www/vendor/laravel/framework/src/Illuminate/Validation/Concerns/ValidatesAttributes.php:687
#59 Illuminate\Validation\Validator:validateUnique in /var/www/vendor/laravel/framework/src/Illuminate/Validation/Validator.php:373
#58 Illuminate\Validation\Validator:validateAttribute in /var/www/vendor/laravel/framework/src/Illuminate/Validation/Validator.php:268
#57 Illuminate\Validation\Validator:passes in /var/www/vendor/laravel/framework/src/Illuminate/Validation/Validator.php:293
#56 Illuminate\Validation\Validator:fails in /var/www/vendor/laravel/framework/src/Illuminate/Validation/Validator.php:305
#55 Illuminate\Validation\Validator:validate in /var/www/vendor/laravel/framework/src/Illuminate/Foundation/Validation/ValidatesRequests.php:47
#54 App\Http\Controllers\Controller:validate in /var/www/app/Http/Controllers/SignUpController.php:74
#53 App\Http\Controllers\SignUpController:memberSignUp in /var/www/vendor/laravel/framework/src/Illuminate/Routing/Controller.php:54
#52 call_user_func_array in /var/www/vendor/laravel/framework/src/Illuminate/Routing/Controller.php:54
#51 Illuminate\Routing\Controller:callAction in /var/www/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php:45
#50 Illuminate\Routing\ControllerDispatcher:dispatch in /var/www/vendor/laravel/framework/src/Illuminate/Routing/Route.php:212
#49 Illuminate\Routing\Route:runController in /var/www/vendor/laravel/framework/src/Illuminate/Routing/Route.php:169
#48 Illuminate\Routing\Route:run in /var/www/vendor/laravel/framework/src/Illuminate/Routing/Router.php:679
#47 Illuminate\Routing\Router:Illuminate\Routing\{closure} in /var/www/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:30
#46 Illuminate\Routing\Pipeline:Illuminate\Routing\{closure} in /var/www/app/Http/Middleware/BoxMiddleware.php:28
#45 App\Http\Middleware\BoxMiddleware:handle in /var/www/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:151
#44 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline\{closure} in /var/www/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:53
#43 Illuminate\Routing\Pipeline:Illuminate\Routing\{closure} in /var/www/vendor/laravel/framework/src/Illuminate/Routing/Middleware/SubstituteBindings.php:41
#42 Illuminate\Routing\Middleware\SubstituteBindings:handle in /var/www/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:151
#41 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline\{closure} in /var/www/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:53
#40 Illuminate\Routing\Pipeline:Illuminate\Routing\{closure} in /var/www/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/VerifyCsrfToken.php:75
#39 Illuminate\Foundation\Http\Middleware\VerifyCsrfToken:handle in /var/www/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:151
#38 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline\{closure} in /var/www/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:53
#37 Illuminate\Routing\Pipeline:Illuminate\Routing\{closure} in /var/www/vendor/laravel/framework/src/Illuminate/View/Middleware/ShareErrorsFromSession.php:49
#36 Illuminate\View\Middleware\ShareErrorsFromSession:handle in /var/www/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:151
#35 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline\{closure} in /var/www/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:53
#34 Illuminate\Routing\Pipeline:Illuminate\Routing\{closure} in /var/www/vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php:63
#33 Illuminate\Session\Middleware\StartSession:handle in /var/www/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:151
#32 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline\{closure} in /var/www/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:53
#31 Illuminate\Routing\Pipeline:Illuminate\Routing\{closure} in /var/www/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/AddQueuedCookiesToResponse.php:37
#30 Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse:handle in /var/www/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:151
#29 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline\{closure} in /var/www/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:53
#28 Illuminate\Routing\Pipeline:Illuminate\Routing\{closure} in /var/www/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/EncryptCookies.php:66
#27 Illuminate\Cookie\Middleware\EncryptCookies:handle in /var/www/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:151
#26 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline\{closure} in /var/www/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:53
#25 Illuminate\Routing\Pipeline:Illuminate\Routing\{closure} in /var/www/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:104
#24 Illuminate\Pipeline\Pipeline:then in /var/www/vendor/laravel/framework/src/Illuminate/Routing/Router.php:681
#23 Illuminate\Routing\Router:runRouteWithinStack in /var/www/vendor/laravel/framework/src/Illuminate/Routing/Router.php:656
#22 Illuminate\Routing\Router:runRoute in /var/www/vendor/laravel/framework/src/Illuminate/Routing/Router.php:622
#21 Illuminate\Routing\Router:dispatchToRoute in /var/www/vendor/laravel/framework/src/Illuminate/Routing/Router.php:611
#20 Illuminate\Routing\Router:dispatch in /var/www/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php:176
#19 Illuminate\Foundation\Http\Kernel:Illuminate\Foundation\Http\{closure} in /var/www/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:30
#18 Illuminate\Routing\Pipeline:Illuminate\Routing\{closure} in /var/www/vendor/fideloper/proxy/src/TrustProxies.php:57
#17 Fideloper\Proxy\TrustProxies:handle in /var/www/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:151
#16 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline\{closure} in /var/www/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:53
#15 Illuminate\Routing\Pipeline:Illuminate\Routing\{closure} in /var/www/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php:31
#14 Illuminate\Foundation\Http\Middleware\TransformsRequest:handle in /var/www/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:151
#13 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline\{closure} in /var/www/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:53
#12 Illuminate\Routing\Pipeline:Illuminate\Routing\{closure} in /var/www/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php:31
#11 Illuminate\Foundation\Http\Middleware\TransformsRequest:handle in /var/www/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:151
#10 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline\{closure} in /var/www/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:53
#9 Illuminate\Routing\Pipeline:Illuminate\Routing\{closure} in /var/www/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/ValidatePostSize.php:27
#8 Illuminate\Foundation\Http\Middleware\ValidatePostSize:handle in /var/www/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:151
#7 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline\{closure} in /var/www/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:53
#6 Illuminate\Routing\Pipeline:Illuminate\Routing\{closure} in /var/www/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/CheckForMaintenanceMode.php:62
#5 Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode:handle in /var/www/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:151
#4 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline\{closure} in /var/www/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:53
#3 Illuminate\Routing\Pipeline:Illuminate\Routing\{closure} in /var/www/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:104
#2 Illuminate\Pipeline\Pipeline:then in /var/www/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php:151
#1 Illuminate\Foundation\Http\Kernel:sendRequestThroughRouter in /var/www/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php:116
#0 Illuminate\Foundation\Http\Kernel:handle in /var/www/public/index.php:55

我可能只是忽略了一些内容,但是经过一个小时的调试,我决定发布一个问题。谢谢! :)

2 个答案:

答案 0 :(得分:0)

在使用laravel-doctrine的类型中,验证接受两个参数:

Documentation说:

/**
 * Store a new blog post.
 *
 * @param  Request  $request
 * @return Response
 */
public function store(Request $request)
{
    $this->validate($request, [
        'username' => 'required|unique:App\User,username',
    ]);
}

因此,您的情况:

$this->validate($request, [
        'email' => 'required|unique:App\User,email',
    ]);

答案 1 :(得分:0)

以下是解决我的问题的方法:

我的卖方文件夹中还剩下laravel-doctrine/orm的一部分,可能是因为我删除了依赖性,但从未运行过作曲家来反映这些更改。因此,运行composer install可以解决我的问题!