Reputation: 92
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
Upvotes: 0
Views: 997
Reputation: 36
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));
}
Upvotes: 1