这就是我如何删除一条记录,你能否建议我什么是删除记录的最佳方法。删除用户相关模型记录的最佳方法
public function delete_post($id) {
//Check if id is numeric and exists
if((is_numeric($id)) && (!empty($id)))
{
$post = Post::find($id);
// check if this id belongs to user (User has author)
if(Auth::id() == $post->user_id){
Post::with('likes')->whereId($id)->delete();
}else{
Session::flash('error', 'You can't delete this.
}
}else{
Session::flash('error', 'Problem with your input');
}
}
是的,我们可以在交易这个包起来为好,但我需要删除用户记录最好的办法。 –