As it is right now ->join() is a query builder so it wouldn’t using Model that has SoftDelete, there is too many codes that used join in my project so I don’t want to manually replace it all with eager loading ->with(), anyone know how to do it while keeping the join?
For example I want to get a data like this without adding ->where(‘tb_b.deleted_at’, null) to all my codes:
$data = TabelA::join('tb_b', 'tb_a.id_b', '=', 'tb_b.id_b')->get()
2
Answers
Three alternatives
There are basically two ways to solve this
Then, you will do this when you need your data without the deleted data
Read more on Laravel scope here: https://learn2torials.com/a/laravel8-global-model-scope