我正在尝试从管理面板中删除评论。我具有删除评论的功能,但是我不知道为什么这不起作用。
这是我的控制人:
$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'));
我的删除评论功能:
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::get('admin/article/deleteComment/{type?}/{id?}', 'ArticleController@deleteComment');
我的按钮
<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>
答案 0 :(得分:1)
您应该尝试以下操作:
请像这样更改路线
Route::get('admin/article/deleteComment/{type}/{id}', 'ArticleController@deleteComment')->name('commentdelete');
您的按钮类似:
<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>
答案 1 :(得分:0)
尝试一下
{!! 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() !!}
创建这样的路线
Route::delete('comments/{id}',['uses'=>'CommentsController@destroy', 'as' => 'comments.destroy']);