在null上调用成员函数pass()

时间:2016-03-20 17:18:30

标签: php laravel laravel-5.2

我确实感觉我需要使用Auth ::或其他东西链接到传递。我是否正确

问题专栏

    if($validator->passes())

`     的 getLoginCredentials

protected function getLoginCredentials(Request $request)
  {
    $validator = $this->loginValidation($request);

    if($validator->passes())
    {
    return[
    'email'    => Request::input('email'),
    'password' => Request::input('password'),
    'type'     => 1  
    ];

    }else{
        return redirect()->back()->withErrors();
    }
  }

loginValidation

protected function loginValidation($request)
    {
        $rules = array(
          'email'      => 'required|email',
          'password'   => 'required',
    );
        $this->validate( $request , $rules);
    }

1 个答案:

答案 0 :(得分:1)

我认为实际问题出在应该返回对象的loginValidation方法中。请看下面的代码。我已经改变了getLoginCredentials,因为Request不应该被静态调用。

protected function getLoginCredentials(Request $request)
{
    $validator = $this->loginValidation($request);

    if ($validator->passes()) {
        return [
            'email'    => $request->input('email'),
            'password' => $request->input('password'),
            'type'     => 1  
        ];
    } else {
        return redirect()->back()->withErrors();
    }
}

<强> loginValidation

protected function loginValidation(Request $request)
{
    $rules = [
      'email'      => 'required|email',
      'password'   => 'required',
    ];
    return Validator::make($request->all(), $rules);
}