我有以下表格: users
id|name|username
Areas
id|name
user_area
id|user_id|area_id
Buildings
id|name|area_id
在用戶模式我想打電話查詢,每一個用戶都有自己的指定區域,並分配給他的領域有許多建築,所以我創建了一個方法查詢用戶分配建築物的用戶模型。 在應用程序\用戶模型: public f
我只想弄清楚我是否想使用存儲庫模式。 的三大優勢,我能找到: 1. Testability (repositories can be injected into the controller)
2. Abstraction (complex eloquent queries can be refactored into repository functions)
3. Decoupling (
我在應用程序\用戶模型文件中的以下方法 Public function buildings(){
return Building::whereHas('area', function ($q) {
$q->whereHas('users', function ($q) {
$q->where('users.id', auth()->id());