Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Laravel路由:{closure}()/未定义变量id缺少参数1_Php_Variables_Laravel 3 - Fatal编程技术网

Php Laravel路由:{closure}()/未定义变量id缺少参数1

Php Laravel路由:{closure}()/未定义变量id缺少参数1,php,variables,laravel-3,Php,Variables,Laravel 3,我正在我的应用程序中实现post版本。我带着这个密码来的: 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'

我正在我的应用程序中实现post版本。我带着这个密码来的:

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}()缺少参数1。在谷歌上搜索一下,我似乎找不到解决办法。已删除函数中的“$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);})); 

我不熟悉L3,但我认为您可以做/验证:

修正你的编辑路线 您忘记了
函数($id)
中的
(:num)
$id

检查你的表格
我不太确定您想要完成什么,我也不熟悉L3,但通常您需要在表单标记中包含
method='PUT'
,以告诉Laravel它实际上是一个PUT路由。如果你的问题与此无关,那么忽略它。此外,您通常还应将所有登录信息包含在控制器中。这将使您的routes文件变得笨拙。这只是我的routes.php文件中的一个片段。我实际工作登录/注册和添加张贴表单。现在,需要的是使文章可编辑:)我做了,但现在拉威尔一直说404.404,因为这个注册表/项目不存在。要检查这一点,请在数据库中为此
$id
@user3235936进行选择,仅用于测试。验证URL,检查路由中的参数(尝试执行
echo$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');