【问题标题】:Class App\Http\Controllers\Auth\Request does not exist. Laravel 5.3类 App\Http\Controllers\Auth\Request 不存在。拉拉维尔 5.3
【发布时间】:2017-02-07 08:28:46
【问题描述】:

我正在使用 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;
}

我可以将链接发送到我的电子邮件,但是一旦我单击链接/按钮。 它会引发类似上面的错误。有什么想法吗?

【问题讨论】:

标签: php laravel


【解决方案1】:

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

use Illuminate\Http\Request;

您收到错误是因为您的脚本尝试从当前命名空间加载Request 类:App\Http\Controllers\Auth

Request docs for Laravel 5.3

【讨论】:

  • 它可以工作,但会引发另一个错误,正如您在上面看到的我的 ForgotPasswordController 返回紧凑。在 ResetPasswordContorller 我尝试使用此代码返回视图 return view('password.resetPassword')->with( ['title' => $title 'appName' => $appName 'action' => $action 'token' => $token, 'email' => $request->email] );结果:语法错误,意外的 ''appName'' (T_CONSTANT_ENCAPSED_STRING),期待 ']'
  • 你错过了',' return view('password.resetPassword')->with( ['title' => $title, 'appName' => $appName, 'action' => $action , 'token' => $token, 'email' => $request->email] );
  • @ka_lin 抱歉,我忘记添加这个 (,) 但现在出现错误未定义变量:两个控制器的标题都扩展到 BaseController。这是我的 BaseController 代码:
  • 你不需要标题,做一个布局(它会有标题),你可以在扩展时覆盖它。 Appname 应该来自配置,并且可以使用 HTML 外观解析操作名称(参见laravel-recipes.com/recipes/190/…
  • 优秀。像魅力一样工作
猜你喜欢
  • 2017-06-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-10-21
  • 2019-03-07
  • 1970-01-01
  • 2014-09-18
相关资源
最近更新 更多