mirror of https://github.com/4xmen/xshop.git
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
1.1 KiB
PHTML
40 lines
1.1 KiB
PHTML
5 months ago
|
<?php
|
||
|
|
||
|
namespace App\Http\Resources;
|
||
|
|
||
|
use App\Models\Category;
|
||
|
use App\Models\Product;
|
||
|
use Illuminate\Http\Request;
|
||
|
use Illuminate\Http\Resources\Json\JsonResource;
|
||
|
|
||
|
//use Illuminate\Http\Resources\Json\ResourceCollection;
|
||
|
|
||
|
class CategoryResource extends JsonResource
|
||
|
{
|
||
|
/**
|
||
|
* Transform the resource collection into an array.
|
||
|
*
|
||
|
* @return array<int|string, mixed>
|
||
|
*/
|
||
|
public function toArray(Request $request, $data = null): array
|
||
|
{
|
||
|
/**
|
||
|
* @var $this Category
|
||
|
*/
|
||
|
$request->merge([
|
||
|
'loadCategory' => false
|
||
|
]);
|
||
|
return [
|
||
|
'id' => $this->id,
|
||
|
'name' => $this->name,
|
||
|
'slug' => $this->slug,
|
||
|
'subtitle' => $this->subtitle,
|
||
|
'description' => $this->description,
|
||
|
'sort' => $this->sort,
|
||
|
'image' => $this->image,
|
||
|
'bg' => $this->bg,
|
||
|
'products' => $this->when($request->input('loadProduct' , true) , ProductResource::collection($this->products)->additional(['request' => $request['loadCategory']]) )
|
||
|
];
|
||
|
}
|
||
|
}
|