9 months ago

error on WithTrashed()

Posted 9 months ago by FareedR

basically i have Post & Deal model which is Post hasMany Deal and Deal belongsTo Post . Below is my current code, i used withTrashed() to get all post that has been deleted by user_id . did i use it correct way ? note that i already use SoftDeletes on Model

// database
id | title | deleted_at
1   asd     timestamps

id | post_id | transaction | etc ....
1   1       2

// controller
$user_id = auth()->id();
$deals = Deal::with('ratings')->whereHas('post', function ($query) use ($user_id) {
    $query->where('user_id', $user_id)->withTrashed();
})->orWhere('buyer_id', $user_id)->get();

Please sign in or create an account to participate in this conversation.