codigo actual del servidor, con avances de joan
This commit is contained in:
36
app/Http/CategoryCollection.php
Normal file
36
app/Http/CategoryCollection.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources\V2;
|
||||
|
||||
use Illuminate\Http\Resources\Json\ResourceCollection;
|
||||
use App\Utility\CategoryUtility;
|
||||
|
||||
class CategoryCollection extends ResourceCollection
|
||||
{
|
||||
public function toArray($request)
|
||||
{
|
||||
return [
|
||||
'data' => $this->collection->map(function($data) {
|
||||
return [
|
||||
'id' => $data->id,
|
||||
'name' => $data->getTranslation('name'),
|
||||
'banner' => uploaded_asset($data->banner),
|
||||
'icon' => uploaded_asset($data->icon),
|
||||
'number_of_children' => CategoryUtility::get_immediate_children_count($data->id),
|
||||
'links' => [
|
||||
'products' => route('api.products.category', $data->id),
|
||||
'sub_categories' => route('subCategories.index', $data->id)
|
||||
]
|
||||
];
|
||||
})
|
||||
];
|
||||
}
|
||||
|
||||
public function with($request)
|
||||
{
|
||||
return [
|
||||
'success' => true,
|
||||
'status' => 200
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user