mirror of
https://github.com/InvoiceShelf/InvoiceShelf.git
synced 2026-09-06 07:11:09 +00:00
feat(catalog,contacts): fresh catalog and contacts implementation
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domains\Catalog\Http\Resources;
|
||||
|
||||
use App\Domains\Accounts\Http\Resources\CompanyResource;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
/**
|
||||
* The payload for a measurement unit: its identity plus the company it
|
||||
* belongs to.
|
||||
*
|
||||
* The owning company is expanded only when the relation resolves, so the
|
||||
* `company` key is absent -- not null -- for a unit whose company row is
|
||||
* missing. Checking that costs an existence query per serialised unit.
|
||||
*/
|
||||
class UnitResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param Request $request
|
||||
*/
|
||||
public function toArray($request): array
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'name' => $this->name,
|
||||
'company_id' => $this->company_id,
|
||||
'company' => $this->when(
|
||||
$this->company()->exists(),
|
||||
fn () => new CompanyResource($this->company)
|
||||
),
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user