This commit is contained in:
merdan 2021-10-28 20:30:35 +05:00
parent 18732157b8
commit e5b75a92ef
6 changed files with 79 additions and 5 deletions

View File

@ -14,8 +14,4 @@ class Categories extends CategoryController
);
}
public function brands($id)
{
}
}

View File

@ -0,0 +1,19 @@
<?php
namespace Sarga\API\Http\Controllers;
use Webkul\API\Http\Controllers\Shop\ResourceController;
class Resources extends ResourceController
{
public function get($code){
$query = isset($this->_config['authorization_required']) && $this->_config['authorization_required'] ?
$this->repository->where(['customer_id'=>auth()->user()->id,'code'=>$code])->first() :
$this->repository->where('code',$code)->first();
if($query)
return new $this->_config['resource']($query);
else
return response()->json(['status'=>false,'message'=>'Not found'],404);
}
}

View File

@ -0,0 +1,25 @@
<?php
namespace Sarga\API\Http\Resources\Catalog;
use Illuminate\Http\Resources\Json\JsonResource;
class Attribute extends JsonResource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request
* @return array
*/
public function toArray($request): array
{
return [
'id' => $this->id,
'code' => $this->code,
'name' => $this->name,
'options' => AttributeOption::collection($this->options),
];
}
}

View File

@ -0,0 +1,25 @@
<?php
namespace Sarga\API\Http\Resources\Catalog;
use Illuminate\Http\Resources\Json\JsonResource;
class AttributeOption extends JsonResource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request
* @return array
*/
public function toArray($request): array
{
return [
'id' => $this->id,
// 'admin_name' => $this->admin_name,
'label' => $this->label,
// 'swatch_value' => $this->swatch_value,
'image' => $this->swatch_value_url
];
}
}

View File

@ -19,7 +19,7 @@ class Category extends JsonResource
'id' => $this->id,
// 'code' => $this->code,
'name' => $this->name,
// 'slug' => $this->slug,
'slug' => $this->slug,
// 'display_mode' => $this->display_mode,
'description' => $this->description,
// 'status' => $this->status,

View File

@ -2,6 +2,9 @@
use Sarga\API\Http\Controllers\Categories;
use Sarga\API\Http\Controllers\Channels;
use Sarga\API\Http\Controllers\Resources;
use Webkul\Attribute\Repositories\AttributeRepository;
use Sarga\API\Http\Resources\Catalog\Attribute;
Route::group(['prefix' => 'api'], function ($router) {
Route::group(['middleware' => ['locale', 'currency']], function ($router) {
@ -12,5 +15,11 @@ Route::group(['prefix' => 'api'], function ($router) {
Route::get('descendant-categories', [Categories::class, 'index']);
Route::get('category-brands/{id}', [Categories::class, 'brands']);
//attributes by code
Route::get('attribute-by-code/{code}', [Resources::class, 'get'])->defaults('_config', [
'repository' => AttributeRepository::class,
'resource' => Attribute::class,
]);
});
});