Skip to content

Commit

Permalink
[SampleResource Step:1] use Carbon to format created_at property
Browse files Browse the repository at this point in the history
  • Loading branch information
rapha-developer committed Jun 2, 2023
1 parent d22cb58 commit 3cf67db
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions app/Http/Resources/SamplesResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Http\Resources;

use App\Utils\DateFormatWithMessage;
use Carbon\Carbon;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;

Expand All @@ -16,13 +17,17 @@ class SamplesResource extends JsonResource
public function toArray(Request $request): array
{
$objDateFormat = new DateFormatWithMessage($this->created_at);

$time = Carbon::make($this->created_at)->format('h A');
$atTime = join(' ', ['AT', $time]);
return [
'id' => (string) $this->id,
'attributes' => [
'title' => $this->title,
'description' => $this->description,
'created_at' => $objDateFormat->message
'created_at' => [
'date' => $objDateFormat->message,
'time' => $atTime
],
],
'display' => [
'title' => 'Example',
Expand Down

0 comments on commit 3cf67db

Please sign in to comment.