這就是我如何刪除一條記錄,你能否建議我什麼是刪除記錄的最佳方法。刪除用戶相關模型記錄的最佳方法
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');
}
}
是的,我們可以在交易這個包起來爲好,但我需要刪除用戶記錄最好的辦法。 –