【问题标题】:Laravel - No query results for modelLaravel - 没有模型的查询结果
【发布时间】:2015-04-25 06:49:56
【问题描述】:

当我尝试使用此查询查找用户时,出现错误“没有模型 [App\User] 的查询结果。”。

        if(User::where('email', '=', Request::only('email'))->firstOrFail()){
        $validator->errors()->add(...);
    }

【问题讨论】:

    标签: php laravel eloquent


    【解决方案1】:

    Request::only() 实际上会返回一个数组。在您的情况下:['email' => 'the-value-of-email']。要么这样做:

    User::where(Request::only('email'))->firstOrFail()
    

    或者只使用Request::input() 只检索值:

    User::where('email', '=', Request::input('email'))->firstOrFail()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-09-16
      • 1970-01-01
      • 2019-12-04
      • 1970-01-01
      • 2014-12-26
      相关资源
      最近更新 更多