이것은 레코드를 삭제하는 방법입니다. 레코드를 삭제하는 가장 좋은 방법은 무엇입니까? Laravel Transactions :사용자 관련 모델 레코드를 삭제하는 가장 좋은 방법
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');
}
}
그래, 우리는 거래에서 이것을 포장 할 수 있습니다뿐만 아니라 있는지 확인할 필요 없다,하지만 난 사용자 레코드를 삭제하는 가장 좋은 방법이 필요합니다. –