I don't want to use the exact date format that the Eloquent model returns when model is typecasted as an array.
Here's a quick code example:
public function show( Request $request, $order_id )
{
$order = Order::find( $order_id );
if( !$order )
return response()->json( [ "message" => "There are no Orders by the selected order ID.","code" => 400 ],400 );
return response()->json( [ "message" => "success","data" => $output,"code" => 200 ], 200 );
}
Here's the data structure / model table:
+------------+--------------+---------------------+
| Field | Type | Default |
+------------+--------------+---------------------+
| id | int(10) | None |
| status | varchar(255) | NULL |
| label | varchar(255) | NULL |
| order_date | date | None |
| created_at | timestamp | 0000-00-00 00:00:00 |
| updated_at | timestamp | 0000-00-00 00:00:00 |
+------------+--------------+---------------------+
Here's the received JSON package:
{
"message": "success",
"data": {
"id": "139",
"status": "NEW",
"label": "Home Inspection",
"order_date": "2016-02-24",
"created_at": "2016-04-27 20:26:41",
"updated_at": "2016-04-27 20:26:41"
},
"code": 200
}
Currently, all dates are sent to the browser as either Y-m-d or Y-m-d H:i:s.
I'd like to send all dates, by default, in a different date format. What's the best way to go about this?