api
This commit is contained in:
parent
63f1adb70d
commit
e351b69f7f
2
.env
2
.env
|
|
@ -1,5 +1,5 @@
|
|||
APP_DEBUG=true
|
||||
APP_URL=http://localhost
|
||||
APP_URL=http://localhost:8000
|
||||
APP_KEY=base64:l9GsGrhw5RLlAybs8em56Jr0ZfzSV25SmoZPB6LiVJQ==
|
||||
|
||||
DB_CONNECTION=mysql
|
||||
|
|
|
|||
|
|
@ -23,16 +23,26 @@ 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 [];}
|
||||
|
|
|
|||
|
|
@ -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')
|
||||
|
|
|
|||
|
|
@ -0,0 +1,47 @@
|
|||
<?php namespace AhmadFatoni\ApiGenerator\Controllers\API;
|
||||
|
||||
use Cms\Classes\Controller;
|
||||
use BackendMenu;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use AhmadFatoni\ApiGenerator\Helpers\Helpers;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Akami\Coffe30\Models\Slider;
|
||||
class SliderAPIController extends Controller
|
||||
{
|
||||
protected $Slider;
|
||||
|
||||
protected $helpers;
|
||||
|
||||
public function __construct(Slider $Slider, Helpers $helpers)
|
||||
{
|
||||
parent::__construct();
|
||||
$this->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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -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 () {
|
||||
|
|
|
|||
Loading…
Reference in New Issue