改进 user 字段处理

This commit is contained in:
iVampireSP.com 2023-01-02 20:12:32 +08:00
parent 30ae62b2e6
commit d9b648d2e4
No known key found for this signature in database
GPG Key ID: 2F7B001CA27A8132
2 changed files with 8 additions and 3 deletions

View File

@ -18,9 +18,7 @@ class ReplyController extends Controller
*/ */
public function index(WorkOrder $workOrder) public function index(WorkOrder $workOrder)
{ {
$replies = Reply::workOrderId($workOrder->id)->with(['module'])->with(['user' => function ($query) { $replies = Reply::workOrderId($workOrder->id)->with('module')->withUser()->simplePaginate(20);
$query->select('id', 'name', 'email');
}])->simplePaginate(10);
return $this->success($replies); return $this->success($replies);
} }

View File

@ -145,4 +145,11 @@ public function scopeWorkOrderId($query, $work_order_id)
{ {
return $query->where('work_order_id', $work_order_id); return $query->where('work_order_id', $work_order_id);
} }
public function scopeWithUser($query)
{
return $query->with(['user' => function ($query) {
$query->select('id', 'name', 'email');
}]);
}
} }