41 lines
883 B
PHP
41 lines
883 B
PHP
<?php
|
|||
|
|
|
||
|
|
namespace App\Http\Resources;
|
||
|
|
|
||
|
|
use Illuminate\Http\Request;
|
||
|
|
use Illuminate\Http\Resources\Json\JsonResource;
|
||
|
|
|
||
|
|
class JobLocationResource extends JsonResource
|
||
|
|
{
|
||
|
|
/**
|
||
|
|
* Transform the resource into an array.
|
||
|
|
*
|
||
|
|
* @return array<string, mixed>
|
||
|
|
*/
|
||
|
|
public function toArray(Request $request): array
|
||
|
|
{
|
||
|
|
return [
|
||
|
|
'id' => $this->id,
|
||
|
|
'city' => $this->city,
|
||
|
|
'state' => $this->state,
|
||
|
|
'country' => $this->country,
|
||
|
|
'country_code' => $this->country_code,
|
||
|
|
'formatted' => $this->formatted(),
|
||
|
|
];
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Format location as a readable string
|
||
|
|
*/
|
||
|
|
private function formatted(): string
|
||
|
|
{
|
||
|
|
$parts = array_filter([
|
||
|
|
$this->city,
|
||
|
|
$this->state,
|
||
|
|
$this->country,
|
||
|
|
]);
|
||
|
|
|
||
|
|
return implode(', ', $parts);
|
||
|
|
}
|
||
|
|
}
|