- add support for console
This commit is contained in:
parent
5b71fa9781
commit
f500c8691f
@ -9,16 +9,23 @@ use Illuminate\Http\Resources\Json\JsonResource;
|
|||||||
class CVResource extends JsonResource
|
class CVResource extends JsonResource
|
||||||
{
|
{
|
||||||
public static $wrap = null;
|
public static $wrap = null;
|
||||||
|
|
||||||
|
private bool $isConsole = false;
|
||||||
|
|
||||||
public function toArray($request): array
|
public function toArray($request = null): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
|
'id' => $this->when($this->isConsole, fn (): int => $this->id),
|
||||||
'token' => $this->token,
|
'token' => $this->token,
|
||||||
'email' => $this->email,
|
'email' => $this->email,
|
||||||
'phoneNumber' => $this->phoneNumber,
|
'recipient' => $this->when($this->isConsole, fn (): string => $this->recipient),
|
||||||
'formattedPhoneNumber' => $this->formattedPhoneNumber,
|
|
||||||
'phone' => new PhoneResource($this->resource),
|
'phone' => new PhoneResource($this->resource),
|
||||||
'locations' => $this->locations,
|
'locations' => $this->locations,
|
||||||
|
'views' => $this->when(
|
||||||
|
$this->isConsole,
|
||||||
|
fn (): int => $this->resource->info()->select('id')->get()->count()
|
||||||
|
),
|
||||||
|
'registeredViews' => $this->when($this->isConsole, fn (): int => $this->views),
|
||||||
'mission' => $this->when(
|
'mission' => $this->when(
|
||||||
!is_null($this->mission),
|
!is_null($this->mission),
|
||||||
fn (): array => explode(PHP_EOL, $this->mission, 5)
|
fn (): array => explode(PHP_EOL, $this->mission, 5)
|
||||||
@ -33,4 +40,11 @@ class CVResource extends JsonResource
|
|||||||
),
|
),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function setAsConsole(): self
|
||||||
|
{
|
||||||
|
$this->isConsole = true;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user