wyyl/beike/Admin/Http/Resources/LogisticsResource.php

48 lines
1.9 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace Beike\Admin\Http\Resources;
use Beike\Repositories\CountryRepo;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
class LogisticsResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @param Request $request
* @return array
* @throws \Exception
*/
public function toArray($request): array{
$countryIds = (array)explode(',',$this->country_ids);
$countryList = CountryRepo::getInList($countryIds);
$countryNames = implode('',array_column($countryList,'name'));
$data = [
'id' => $this->id,
'name' => $this->name ?? '',
'warehouse_name' => $this->warehouse_name ?? '',
'country_id' => $this->country_id,
'country' => $countryNames,//$this->country ? $this->country->name : '',
'type' => $this->type,
'first_weight' => $this->first_weight,
'first_weight_fee' => $this->first_weight_fee,
'continuation_weight_max' => $this->continuation_weight_max,
'add_weight' => $this->add_weight,
'continuation_weight_fee' => $this->continuation_weight_fee,
'num_fee' => $this->num_fee,
'throwing_ratio' => $this->throwing_ratio,
'day_min' => $this->day_min,
'day_max' => $this->day_max,
'position' => $this->position,
'created_at' => time_format($this->created_at),
'deleted_at' => $this->deleted_at ? time_format($this->deleted_at) : '',
'url_edit' => admin_route('logistics.edit', $this->id),
];
return hook_filter('resource.product', $data);
}
}