我有一个关于 Laravel 表单的问题,我的项目结构如下:
controllers/
administration/
NewsController.php
在 NewsController 中,我有一个名为 postCreate() 的方法:
public function postCreate(){
$validator = Validator::make(Input::all(), \News::$rules);
if($validator->passes()){
$news = new \News();
$news->title = Input::get('title');
$news->content = Input::get('content');
$news->author = Input::get('author');
$news->type = Input::get('type');
$image = Input::file('file');
$filename = time().".".$image->getClientOriginalExtension();
$path = public_path('content/images/' . $filename);
Image::make($image->getRealPath())->resize(468,249)->save($path);
$news->image = 'content/images/'.$filename;
$news->save();
return Redirect::to('/administration/news/add')
->with('message','Succes');
}
return Redirect::to('/administration/news/add')
->with('message','Error')
->withErrors($validator)
->withInput();
}
我的表单具有行动:
{{ Form::open(array('url'=>'administration/news/create', 'files'=>true)) }}
{{ Form::close() }}
我的路由:
Route::post('/administration/news/create', array('uses'=>'App\Controllers\Administration \NewsController@postCreate'));
但是当我提交时,会出现错误:
Symfony \ Component \ HttpKernel \ Exception \ NotFoundHttpException
我不明白我的问题出在哪里。
post
或get
。 - Jerodev