mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/portal.git
synced 2026-08-25 15:34:24 +00:00
fix address resource loop
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
||||
use App\Models\Order;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
@@ -15,6 +16,7 @@ class AddressResource extends JsonResource
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'reference' => $this->reference,
|
||||
@@ -25,6 +27,15 @@ class AddressResource extends JsonResource
|
||||
'post_code' => $this->postcode,
|
||||
'country' => $this->country,
|
||||
'default' => (int) $this->default,
|
||||
'status' => (int) $this->status,
|
||||
$this->mergeWhen($this->relationLoaded('owner'), [
|
||||
'owner' => $this->when($this->owner instanceof Order, [
|
||||
'reference' => $this->owner->reference,
|
||||
'company_module' => new CompanyModuleResource($this->owner->companyModule),
|
||||
'address' => new AddressResource($this->owner->addresses()->where('status', '=', ApprovalStatus::APPROVED)->first())
|
||||
])
|
||||
])
|
||||
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user