我正在我的应用中实现发布版本。我带来了这段代码:
Route::get('editpost', array('before' => 'auth', 'do' => function($id){
$user = Auth::user();
$view_post = Post::with('user')->find($id);
return View::make('admin.editpost')
->with('user', $user)
->with('post', $view_post);
}));
后来我使用了PUT路线。
但是当我尝试编辑测试帖时,我想出了{closure}()的Missing参数1。通过对Google的一点搜索,我似乎找不到解决方案。删除了函数中的“$ id”和“未定义的变量”。
你介意导致问题的原因吗?这段代码是否正确?
Route::get('editpost', array('before' => 'auth', 'do' => function(){
$user = Auth::user();
$view_post = Post::with('user')->find($id);
return View::make('admin.editpost')
->with('user', $user)
->with('post', $view_post);}));
Route::put('post/(:num)', array('before' => 'auth', 'do' => function($id) {
$edit_post = array(
'post_title' => Input::get('post_title'),
'post_body' => Input::get('post_body'),
'post_author' => Input::get('post_author')
);
$rules = array(
'post_title' => 'required|min:3|max:255',
'post_body' => 'required|min:10'
);
$validation = Validator::make($edit_post, $rules);
if ($validation -> fails()){
return Redirect::to('editpost')
->with('user',Auth::user())
->with_errors($validation)
->with_input();
}
$post = Post::with('user')->find($id);
$post->post_title = $post_title;
$post->post_body = $post_body;
$post->post_author = $post_author;
$post->save();
//go to all post
return Redirect::to('news')->with('success_message', true);}));
答案 0 :(得分:1)
我不熟悉L3,但我认为你可以做/验证:
您忘记了(:num)
中的$id
和function($id)
:
Route::get('editpost/(:num)', array('before' => 'auth', 'do' => function($id){
$user = Auth::user();
$view_post = Post::with('user')->find($id);
return View::make('admin.editpost')
->with('user', $user)
->with('post', $view_post);}));
echo Form::open("post/{$post->id}", 'PUT');