diff --git a/.env b/.env index 3f9a63b7..5af79a2e 100644 --- a/.env +++ b/.env @@ -1,5 +1,5 @@ APP_DEBUG=true -APP_URL=http://localhost +APP_URL=http://localhost:8000 APP_KEY=base64:l9GsGrhw5RLlAybs8em56Jr0ZfzSV25SmoZPB6LiVJQ== DB_CONNECTION=mysql diff --git a/plugins/ahmadfatoni/apigenerator/controllers/api/CategoriesAPIController.php b/plugins/ahmadfatoni/apigenerator/controllers/api/CategoriesAPIController.php index 9a670dd6..9353e6a0 100644 --- a/plugins/ahmadfatoni/apigenerator/controllers/api/CategoriesAPIController.php +++ b/plugins/ahmadfatoni/apigenerator/controllers/api/CategoriesAPIController.php @@ -23,15 +23,25 @@ class CategoriesAPIController extends Controller public function index(){ $data = $this->Category + ->select("id", "name", "slug") + ->orderBy("nest_left", "asc") ->with('translations:locale,model_id,attribute_data') + ->where("nest_depth", 0) ->active() ->get(); - if($data) { - $data->each(function ($item, $key) { - $item->icon = $this->pageUrl('index') . \Config::get('cms.storage.media.path') . $item->icon; - }); - } + return $this->helpers->apiArrayResponseBuilder(200, 'success', $data); + } + + public function GetParent($id){ + + $data = $this->Category + ->select("id", "name", "slug") + ->orderBy("nest_left", "asc") + ->with('translations:locale,model_id,attribute_data') + ->where("parent_id", $id) + ->active() + ->get(); return $this->helpers->apiArrayResponseBuilder(200, 'success', $data); } @@ -48,56 +58,6 @@ class CategoriesAPIController extends Controller } - // public function store(Request $request){ - - // $arr = $request->all(); - - // while ( $data = current($arr)) { - // $this->Category->{key($arr)} = $data; - // next($arr); - // } - - // $validation = Validator::make($request->all(), $this->Category->rules); - - // if( $validation->passes() ){ - // $this->Category->save(); - // return $this->helpers->apiArrayResponseBuilder(201, 'created', ['id' => $this->Category->id]); - // }else{ - // return $this->helpers->apiArrayResponseBuilder(400, 'fail', $validation->errors() ); - // } - - // } - - // public function update($id, Request $request){ - - // $status = $this->Category->where('id',$id)->update($data); - - // if( $status ){ - - // return $this->helpers->apiArrayResponseBuilder(200, 'success', 'Data has been updated successfully.'); - - // }else{ - - // return $this->helpers->apiArrayResponseBuilder(400, 'bad request', 'Error, data failed to update.'); - - // } - // } - - // public function delete($id){ - - // $this->Category->where('id',$id)->delete(); - - // return $this->helpers->apiArrayResponseBuilder(200, 'success', 'Data has been deleted successfully.'); - // } - - // public function destroy($id){ - - // $this->Category->where('id',$id)->delete(); - - // return $this->helpers->apiArrayResponseBuilder(200, 'success', 'Data has been deleted successfully.'); - // } - - public static function getAfterFilters() {return [];} public static function getBeforeFilters() {return [];} public static function getMiddleware() {return [];} diff --git a/plugins/ahmadfatoni/apigenerator/controllers/api/ProductAPIController.php b/plugins/ahmadfatoni/apigenerator/controllers/api/ProductAPIController.php index fb275731..080eb56d 100644 --- a/plugins/ahmadfatoni/apigenerator/controllers/api/ProductAPIController.php +++ b/plugins/ahmadfatoni/apigenerator/controllers/api/ProductAPIController.php @@ -23,10 +23,11 @@ class ProductAPIController extends Controller public function index(){ $data = $this->Product + ->select("id", "name", "slug", "category_id", "featured") ->with('translations:locale,model_id,attribute_data') - ->with(['category' => function ($query) { - $query->with('translations:locale,model_id,attribute_data'); - }]) + // ->with(['category' => function ($query) { + // $query->with('translations:locale,model_id,attribute_data'); + // }]) ->active() ->paginate(10); @@ -39,6 +40,19 @@ class ProductAPIController extends Controller return $this->helpers->apiArrayResponseBuilder(200, 'success', $data); } + public function ByCatId($id){ + + $data = $this->Product + ->select("id", "name", "slug", "category_id", "featured") + ->with('translations:locale,model_id,attribute_data') + ->where("category_id", $id) + ->active() + ->paginate(10); + + return $this->helpers->apiArrayResponseBuilder(200, 'success', $data); + } + + public function show($id){ $data = $this->Product::with('translations:locale,model_id,attribute_data') diff --git a/plugins/ahmadfatoni/apigenerator/controllers/api/SliderAPIController.php b/plugins/ahmadfatoni/apigenerator/controllers/api/SliderAPIController.php new file mode 100644 index 00000000..9cd5d820 --- /dev/null +++ b/plugins/ahmadfatoni/apigenerator/controllers/api/SliderAPIController.php @@ -0,0 +1,47 @@ +Slider = $Slider; + $this->helpers = $helpers; + } + + public function index(){ + + $data = $this->Slider + ->select("id", "img") + ->with('translations:locale,model_id,attribute_data') + ->get(); + + if($data) { + $data->each(function ($item, $key) { + $item->img = $this->pageUrl('index') . \Config::get('cms.storage.media.path') . $item->img; + }); + } + + return $this->helpers->apiArrayResponseBuilder(200, 'success', $data); + } + + + public static function getAfterFilters() {return [];} + public static function getBeforeFilters() {return [];} + public static function getMiddleware() {return [];} + public function callAction($method, $parameters=false) { + return call_user_func_array(array($this, $method), $parameters); + } + +} \ No newline at end of file diff --git a/plugins/ahmadfatoni/apigenerator/routes.php b/plugins/ahmadfatoni/apigenerator/routes.php index 9ef9b6cb..4fc4518b 100644 --- a/plugins/ahmadfatoni/apigenerator/routes.php +++ b/plugins/ahmadfatoni/apigenerator/routes.php @@ -7,9 +7,13 @@ Route::get('fatoni/delete/api/{id}', array('as' => 'fatoni.delete.api', 'uses' = Route::group(['prefix' =>'api/v1','namespace' =>'AhmadFatoni\ApiGenerator\Controllers\API'],function ($route){ Route::get('products','ProductAPIController@index'); + Route::get('products/category/{id}','ProductAPIController@ByCatId'); Route::get('products/{id}', 'ProductAPIController@show'); Route::get('categories', 'CategoriesAPIController@index'); + Route::get('category/sub/{id}', 'CategoriesAPIController@getParent'); + + Route::get('sliders', 'SliderAPIController@index'); Route::middleware([\ReaZzon\JWTAuth\Http\Middlewares\ResolveUser::class])->group(function () {