belogsToMany relation withoutTrashed()? How can I fetch belongsToMany records without trashed rows? for example like:
$consultation->insurances()->withoutTrashed();
is it possible?
Do you have the use SoftDeletes trait in your model? If you do, then that's the default behaviour. You won't need to make without trashed call.
when you use SoftDelete, all the query will append and deleted_at is null
suggest install Laravel-debugbar
@newbie360
yes we have a ConsultationInsurace pivot model and uses SoftDeletes but I have to append wherePivotNull('deleted_at') to relations like
$this->belongsToMany(Insurance::class)->wherePivotNull('deleted_at')->withPivot('percentage');
@FarhadMohammadi so in the pivot table using SoftDelete ? oh, i never doing like that no idea how to handle this
@newbie360 ya :) me neither have no Idea :)
cuz some foreign key cascade we can't hard delete the records and we have to soft delete them, so sync will not work with soft delete and I have to implement it manually.
@FarhadMohammadi why ? if in the pivot table both foreign key is deletable, why not just in migration set both foreign key cascade on delete
Please sign in or create an account to participate in this conversation.