OrderResource.php 1.1 KB

123456789101112131415161718192021222324252627282930313233
  1. <?php
  2. namespace App\Http\Resources\App;
  3. use App\Models\Order;
  4. use Carbon\Carbon;
  5. use Illuminate\Http\Resources\Json\JsonResource;
  6. class OrderResource extends JsonResource
  7. {
  8. /**
  9. * Transform the resource into an array.
  10. *
  11. * @param \Illuminate\Http\Request $request
  12. * @return array
  13. */
  14. public function toArray($request)
  15. {
  16. $model = $this->resource;
  17. $data = [
  18. 'id' => $model->id,
  19. 'no' => $model->no,
  20. 'nickname' => ($model->users->nickname ?? '')."(".($model->users->truename ?? '').")",
  21. 'mobile' => $model->users->mobile ?? '',
  22. 'orders_status' => Order::$statusMaps[$model->status],
  23. 'bike_no' => $model->bike_no,
  24. 'start_use_bike_time' => Carbon::make($model->start_use_bike_time)->format('Y/m/d H:i:s'),
  25. 'end_use_bike_time' => $model->end_use_bike_time ? Carbon::make($model->end_use_bike_time)->format('Y/m/d H:i:s') : '',
  26. 'created_at' => date('Y/m/d H:i:s',strtotime($model->created_at))
  27. ];
  28. return $data;
  29. }
  30. }