![](/img/trans.png)
[英]how do i delete a notification in laravel when a user deletes the comment related to the notification
[英]How do I delete everything related to user with the user account
我想刪除用戶帳戶以及檢查用戶是否包含任何'posts', 'messages', 'friends'
,如果有,我也希望它刪除它們。
我沒有在他們的模型中建立任何關系。
我很難開發這種邏輯,任何人都可以幫助我。
這是我到目前為止所做的但不起作用: -
public function delete()
{
$delete = User::find(Auth::user()->id);
$post = DB::table('posts')
->where('created_by', '=', Auth::user()->uuid)
->get();
$messages = DB::table('messages')
->where('from', '=', Auth::user()->id)
->where('to', '=', Auth::user()->id)
->get();
$friend = DB::table('friends')
->where('my_id', '=', Auth::user()->id)
->where('friends_id', '=', Auth::user()->id)
->get();
$delete->delete();
$post->delete();
$message->delete();
$friend->delete();
}
get()
會給你一個數組,所以delete()
在你使用后可能不起作用->get
。
嘗試這個:
$delete = User::find(Auth::user()->id);
$delete->delete(); // Example of Model
$post = DB::table('posts')
->where('created_by', '=', Auth::user()->uuid)
->delete();
$messages = DB::table('messages')
->where('from', '=', Auth::user()->id)
->where('to', '=', Auth::user()->id)
->delete();
$friend = DB::table('friends')
->where('my_id', '=', Auth::user()->id)
->where('friends_id', '=', Auth::user()->id)
->delete();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.