phase 5
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
<?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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user