Soft-Deletes with Query Builder

Don't forget that soft-deletes will exclude entries when you use Eloquent, but won't work if you use Query Builder.

1// Will exclude soft-deleted entries
2$users = User::all();
3 
4// Will NOT exclude soft-deleted entries
5$users = User::withTrashed()->get();
6 
7// Will NOT exclude soft-deleted entries
8$users = DB::table('users')->get();

Like our articles?

Become a Premium Member for $129/year or $29/month
What else you will get:
  • 22 courses (477 lessons, total 38 h 20 min)
  • 2 long-form tutorials (one new every week)
  • access to project repositories
  • access to private Discord