【问题标题】:ReflectionException in Route.php line 339: Class App\Http\Controllers\ContactRequest does not existRoute.php 第 339 行中的 ReflectionException:App\Http\Controllers\ContactRequest 类不存在
【发布时间】:2017-01-10 11:03:23
【问题描述】:

我正在尝试使用 Laravel 表单请求来实现联系表单,因此我使用代码创建了一个请求:

 class ContactRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'name' => 'required',
            'email' => 'required|email',
            'message' => 'required',
        ];
    }
}

还正确设置了我的路由文件:

Route::get('contact',
['as' => 'contact', 'uses' => 'AboutController@make']);
Route::post('contact',
['as' => 'contact_store', 'uses' => 'AboutController@store']);

但它一直在说:

ReflectionException in Route.php line 339:
Class App\Http\Controllers\ContactRequest does not exist

请帮忙,我该怎么办?

【问题讨论】:

  • 在你的AboutController中检查是否有use App\Http\Requests\ContactRequest;
  • 谢谢,那不见了。它现在可以工作了。但是提交时并没有在表单中显示消息:return \Redirect::route('contact') ->with('message', 'Thanks for contacting us!');
  • 你是在视图中调用变量吗?

标签: laravel


【解决方案1】:

在控制器顶部添加请求类命名空间:

use App\Http\Requests\ContactRequest;

之后你就可以只使用它的类名来注入它:

public function store(ContactRequest $request)

【讨论】:

    猜你喜欢
    • 2016-08-09
    • 1970-01-01
    • 2019-02-20
    • 1970-01-01
    • 2018-11-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-07
    相关资源
    最近更新 更多