类 App\Http\Controllers\Auth\Request 不存在。Laravel 5.3

19

我正在使用 Laravel 5.3,我的 ForgotPasswordController 代码如下:

<?php

namespace App\Http\Controllers\Auth;

use App\Http\Controllers\Base\BaseController;
use Illuminate\Foundation\Auth\SendsPasswordResetEmails;

class ForgotPasswordController extends BaseController
{

use SendsPasswordResetEmails;
public function __construct()
{
    $this->middleware('guest');
}
public function showLinkRequestForm()
{
    $title = $this->title;
    $appName = $this->appName;
    $action = $this->action;
    return view('password.forgotPassword')->with(compact('title', 'appName', 'action'));
}
}

重置密码控制器代码:

<?php

namespace App\Http\Controllers\Auth;

use App\Http\Controllers\Base\BaseController;
use Illuminate\Foundation\Auth\ResetsPasswords;

class ResetPasswordController extends BaseController
{

use ResetsPasswords;
 public function __construct()
{
    $this->middleware('guest');
}

public function showResetForm(Request $request, $token = null)
{
    return view('passwords.resetPassword')->with(
        ['token' => $token, 'email' => $request->email]
    );
}
 public function reset(Request $request)
{
    $this->validate($request, [
        'token' => 'required',
        'password' => 'required|confirmed|min:6',
    ]);

    // Here we will attempt to reset the user's password. If it is successful we
    // will update the password on an actual user model and persist it to the
    // database. Otherwise we will parse the error and return the response.
    $response = $this->broker()->reset(
        $this->credentials($request), function ($user, $password) {
            $this->resetPassword($user, $password);
        }
    );

    // If the password was successfully reset, we will redirect the user back to
    // the application's home authenticated view. If there is an error we can
    // redirect them back to where they came from with their error message.
    return $response == Password::PASSWORD_RESET
                ? $this->sendResetResponse($response)
                : $this->sendResetFailedResponse($request, $response);
}

}

我的管理路由:

Route::group(['namespace' => 'Auth'], function() {
Route::get('/forgotpassword/reset', 'ForgotPasswordController@showLinkRequestForm');
Route::post('/forgotpassword/email', 'ForgotPasswordController@sendResetLinkEmail');
Route::get('/password/reset/{token}', 'ResetPasswordController@showResetForm');
Route::post('/password/reset', 'ResetPasswordController@reset');
});

基础控制器代码:

<?php

namespace App\Http\Controllers\Base;

use App\Http\Controllers\Controller;


class BaseController extends Controller
{
protected $appName = 'Stackoverflow';
protected $title = 'Welcome to Stackoverflow';
protected $action;
}

我可以将链接发送到我的电子邮件中,但是一旦我点击链接/按钮,就会出现像上面这样的错误。有任何想法吗?

我可以将链接发送到我的电子邮件中,但是一旦我点击链接/按钮,就会出现如上所述的错误。有什么想法吗?


可能是[Laravel Request :: all()不应静态调用]的重复问题(https://dev59.com/O14b5IYBdhLWcg3w5VI9) - patricus
1个回答

98

您未使用所需的命名空间,请在您的控制器中尝试使用以下命名空间:

use Illuminate\Http\Request;

您得到此错误的原因是您的脚本尝试从当前命名空间 App\Http\Controllers\Auth 加载 Request 类。

Laravel 5.3 的请求文档


它可以工作,但会抛出另一个错误,正如您在我的ForgotPasswordController中看到的那样,我返回了compact。在ResetPasswordContorller中,我尝试使用以下代码返回视图 return view('password.resetPassword')->with( ['title' => $title 'appName' => $appName 'action' => $action 'token' => $token, 'email' => $request->email] ); 结果:语法错误,意外的''appName''(T_CONSTANT_ENCAPSED_STRING),期望']'。 - Andrew Vanusi
1
你缺少了逗号,应该返回视图('password.resetPassword')->with(['title' => $title, 'appName' => $appName, 'action' => $action, 'token' => $token, 'email' => $request->email]); - Komal
@ka_lin 抱歉,我忘记加逗号了,现在出现错误:未定义变量:title两个控制器都继承自BaseController。 以下是我的BaseController代码: <?phpnamespace App\Http\Controllers\Base;use App\Http\Controllers\Controller;class BaseController extends Controller { protected $appName = 'stackoverflow'; protected $title = '欢迎来到stackoverflow'; protected $action; } - Andrew Vanusi
创建自己的基础控制器(MyBaseController),它继承自App\Http\Controllers\Auth\BaseController,并在其中分配变量(附注:在MyBaseController的构造函数中调用parent::__construct(),如果BaseController有一个的话,我记不清了,也没有项目可以检查)。然后,所有的控制器都应该继承MyBaseController - ka_lin
1
太棒了。像魔法一样运行良好。 - Ale Ponzo
显示剩余3条评论

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接