2017-10-20 69 views
1

我无法找到问题。它在哪里? “未定义的变量:要求”Laravel:未定义变量:请求

public function login() 
{ 
    // Validate the form data 
    $this->validate($request, [ 
    'email' => 'required|email', 
    'passwort' => 'required|min:6' 
    ]); 

    // Attempt to log the user in 
    if (Auth::guard('admin')->attempt(['email' => $request->email, 'passwort' => $request->passwort], $remember)) { 
    // if successful, then redirect to their intended location 
    return redirect()->intended(roue('admin.dashboard')); 
    } 

    // if unsuccessful, then redirect back to the login with the form data 
    return redirect()->back()->withInput($request->only('email', 'remember')); 
} 
+1

好了,非常简单。您尚未定义'请求'变量,但您在代码中使用了它。 – zuif

回答

4

你需要注入Request对象:

public function login(Request $request) 

此外,该行添加到您的类的顶部:

use Illuminate\Http\Request; 

或者,您也可以只需在代码中使用request()而不是$request

1

您尚未定义'请求'变量,但您在代码中使用了它。

编辑代码

public function login(Request $request) 
{ 
    // Validate the form data 
    $this->validate($request, [ 
    'email' => 'required|email', 
    'passwort' => 'required|min:6' 
    ]); 

    // Attempt to log the user in 
    if (Auth::guard('admin')->attempt(['email' => $request->email, 'passwort' => $request->passwort], $remember)) { 
    // if successful, then redirect to their intended location 
    return redirect()->intended(roue('admin.dashboard')); 
    } 

    // if unsuccessful, then redirect back to the login with the form data 
    return redirect()->back()->withInput($request->only('email', 'remember')); 
} 

此外,该行添加到您的类的顶部:

use Illuminate\Http\Request;