我的 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
我不明白我的问题出在哪里。
最佳答案
一个小调整......忘记手动创建地址。
在routes.php中:
Route::post('/administration/news/create',
array('uses'=>'App\Controllers\Administration\NewsController@postCreate',
'as' => 'news.post.create'));
查看中:
{{ Form::open(array('url'=>route('news.post.create'), 'files'=>true)) }}
无需记住任何这些地址。
关于php - Laravel 中的表单操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26887102/