Route.php第339行中的ReflectionException:类App \ Http \ Controllers \ ContactRequest不存在

时间:2017-01-10 11:03:24

标签: laravel

我正在尝试使用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

请帮助,我该怎么办?

1 个答案:

答案 0 :(得分:1)

将请求类命名空间添加到控制器的顶部:

use App\Http\Requests\ContactRequest;

之后,您将能够使用它的类名注入它:

public function store(ContactRequest $request)