Reputation: 251
I am trying to delete comments from my admin panel.I have a function for delete comments but I dont know why this isn't working.
Here is my controller:
$article = \DB::table("events")
->where("id", $id)
->select("id", "subject", "information", "public", "category_id", "event_type_id", "country", "address", "city", "starts", "ends", "organizer", "website", "email", "telephone")
->first();
$data['article'] = $article;
$event_comm = EventComment::where('event_id', $id)->get();
return view("admin.editEvent", $data)
->with(compact('event_comm'));
My delete comments function:
public function deleteComment($type, $id)
{
if($type == "Event")
{
$comment = \App\EventComment::find($id);
}
if($type == "Opinion")
{
$comment = \App\OpinionComment::find($id);
}
$comment->delete();
return redirect('admin/comments');
}
Route for deletecomment
Route::get('admin/article/deleteComment/{type?}/{id?}', 'ArticleController@deleteComment');
My button
<button href="{{ url('admin/article/deleteComment/'.$article['type'].'/'.$article['id']) }}" role="button" class="btn btn-xs btn-danger" onclick="return confirm('Are you sure you want to delete this comment?');">Delete <i class="fa fa-trash"></i></button>
Upvotes: 0
Views: 279
Reputation: 21681
You should try this:
Please change your route like
Route::get('admin/article/deleteComment/{type}/{id}', 'ArticleController@deleteComment')->name('commentdelete');
Your button like:
<button href="{{ route('commentdelete',[$article['type'],$article['id']]) }}" role="button" class="btn btn-xs btn-danger" onclick="return confirm('Are you sure you want to delete this comment?');">Delete <i class="fa fa-trash"></i></button>
Upvotes: 1
Reputation: 1187
Try this
{!! Form::open(['method' => 'DELETE', 'route'=>['comments.destroy', $comment->id], 'style'=> 'display:inline', 'onsubmit' => 'return confirm("Are you sure you want to delete?")']) !!}
{!! Form::button('<i class="fa fa-trash"></i>',['type'=>'submit', 'class'=> 'btn btn-danger']) !!}
{!! Form::close() !!}
Create a route like this
Route::delete('comments/{id}',['uses'=>'CommentsController@destroy', 'as' => 'comments.destroy']);
Upvotes: 0