【发布时间】: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