因此,我有2个名为'主题'和'帖子'的表。从Laravel控制器中的不同标签删除2行
主题是线程和主题的主要内容的答复。
所以,我想如果用户删除它的话题,那么它的下面的回复/帖子也应该删除。
这是我删除形式:
{!! Form::open(['action' => ['[email protected]', $topic->id], 'method' => 'POST', 'class' => 'pull-right']) !!}
{{ Form::hidden('_method', 'DELETE') }}
{{ Form::submit('Delete', ['class' => 'btn btn-danger']) }}
{!! Form::close() !!}
这里是控制器:
$topic = Topic::find($id);
$post = Post::where('topic_id', $id)->get();
$topic->delete();
$post->delete();
return redirect('/')->with('Success', 'Post Removed');
但它给错误:
BadMethodCallException
Method delete does not exist.
有什么做错了这里?
尝试forceDelete()或softDelete(),取决于你想要哪一个 – Cr1xus