dsdqpdjpq16640651 2018-06-17 08:03
浏览 45

laravel中缺少必需参数

I've been trying to get this fixed for days now. I don't know what i'm doing wrong. I'm trying to edit a post in the dashboard. My route looks like this

Route::get('/edit-post/post_id/{post_id}',[
            'as'=>'edit-post',
            'uses'=>'dashboardController@showPostedit',
        ]);

for that route i have a controller

public function showPostEdit(Request $request, Post $post, $post_id){
    $posts= $post->where('post_id',$post_id)->get();

        return view('pages.dashboard.user.edit-post',compact('posts',auth()- 
  >user()->id));
  }

My blade syntax looks like this

  @if(Auth::check())
    @if(auth()->user()->id === $posts->user_id)
        <li class="list-inline-item"><a href="{{route('edit-post',['user_id'=>auth()->user()->id,'post_id'=>$posts->post_id])}}"><span class="fa fa-edit"></span></a></li>
                        <li class="list-inline-item"><a href="{{route('delete-post',$posts->post_id)}}"><span class="fa fa-trash"></span></a></li>
                    @endif
            @endif
  • 写回答

1条回答 默认 最新

  • duanjing7459 2018-06-17 08:43
    关注

    Solution 1: primary key should be id instead of post_id in post table.

    Route::get('/edit-post/{post}',[
            'as'=>'edit-post',
            'uses'=>'dashboardController@showPostEdit',
        ]);
    public function showPostEdit(Post $post){
        return view('pages.dashboard.user.edit-post',compact('post',auth()->user()->id));
       }
    

    Solution 2:

    Route::get('/edit-post/{postId}',[
            'as'=>'edit-post',
            'uses'=>'dashboardController@showPostEdit',
        ]);
    public function showPostEdit($postId){
    $post= (new Post())->where('post_id',$postId)->get();
        return view('pages.dashboard.user.edit-post',compact('post',auth()->user()->id));
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
  • ¥100 连续两帧图像高速减法
  • ¥15 组策略中的计算机配置策略无法下发
  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据
  • ¥20 给自己本科IT专业毕业的妹m找个实习工作
  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
  • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)