@@ -6,29 +6,29 @@ |
||
| 6 | 6 | |
| 7 | 7 | class CreateOauthPersonalAccessClientsTable extends Migration |
| 8 | 8 | { |
| 9 | - /** |
|
| 10 | - * Run the migrations. |
|
| 11 | - * |
|
| 12 | - * @return void |
|
| 13 | - */ |
|
| 14 | - public function up() |
|
| 15 | - { |
|
| 16 | - Schema::create('oauth_personal_access_clients', function (Blueprint $table) { |
|
| 17 | - increments('id'); |
|
| 18 | - $table->unsignedInteger('client_id'); |
|
| 19 | - $table->timestamps(); |
|
| 9 | + /** |
|
| 10 | + * Run the migrations. |
|
| 11 | + * |
|
| 12 | + * @return void |
|
| 13 | + */ |
|
| 14 | + public function up() |
|
| 15 | + { |
|
| 16 | + Schema::create('oauth_personal_access_clients', function (Blueprint $table) { |
|
| 17 | + increments('id'); |
|
| 18 | + $table->unsignedInteger('client_id'); |
|
| 19 | + $table->timestamps(); |
|
| 20 | 20 | |
| 21 | - $table->foreign('client_id')->references('id')->on('oauth_clients'); |
|
| 22 | - }); |
|
| 23 | - } |
|
| 21 | + $table->foreign('client_id')->references('id')->on('oauth_clients'); |
|
| 22 | + }); |
|
| 23 | + } |
|
| 24 | 24 | |
| 25 | - /** |
|
| 26 | - * Reverse the migrations. |
|
| 27 | - * |
|
| 28 | - * @return void |
|
| 29 | - */ |
|
| 30 | - public function down() |
|
| 31 | - { |
|
| 32 | - Schema::drop('oauth_personal_access_clients'); |
|
| 33 | - } |
|
| 25 | + /** |
|
| 26 | + * Reverse the migrations. |
|
| 27 | + * |
|
| 28 | + * @return void |
|
| 29 | + */ |
|
| 30 | + public function down() |
|
| 31 | + { |
|
| 32 | + Schema::drop('oauth_personal_access_clients'); |
|
| 33 | + } |
|
| 34 | 34 | } |
@@ -13,7 +13,7 @@ |
||
| 13 | 13 | */ |
| 14 | 14 | public function up() |
| 15 | 15 | { |
| 16 | - Schema::create('oauth_personal_access_clients', function (Blueprint $table) { |
|
| 16 | + Schema::create('oauth_personal_access_clients', function(Blueprint $table) { |
|
| 17 | 17 | increments('id'); |
| 18 | 18 | $table->unsignedInteger('client_id'); |
| 19 | 19 | $table->timestamps(); |
@@ -6,35 +6,35 @@ |
||
| 6 | 6 | |
| 7 | 7 | class CreateOauthClientsTable extends Migration |
| 8 | 8 | { |
| 9 | - /** |
|
| 10 | - * Run the migrations. |
|
| 11 | - * |
|
| 12 | - * @return void |
|
| 13 | - */ |
|
| 14 | - public function up() |
|
| 15 | - { |
|
| 16 | - Schema::create('oauth_clients', function (Blueprint $table) { |
|
| 17 | - increments('id'); |
|
| 18 | - $table->unsignedInteger('user_id')->nullable(); |
|
| 19 | - $table->string('name'); |
|
| 20 | - $table->string('secret', 100); |
|
| 21 | - $table->text('redirect'); |
|
| 22 | - $table->boolean('personal_access_client')->default(0); |
|
| 23 | - $table->boolean('password_client')->default(0); |
|
| 24 | - $table->boolean('revoked')->default(0); |
|
| 25 | - $table->timestamps(); |
|
| 9 | + /** |
|
| 10 | + * Run the migrations. |
|
| 11 | + * |
|
| 12 | + * @return void |
|
| 13 | + */ |
|
| 14 | + public function up() |
|
| 15 | + { |
|
| 16 | + Schema::create('oauth_clients', function (Blueprint $table) { |
|
| 17 | + increments('id'); |
|
| 18 | + $table->unsignedInteger('user_id')->nullable(); |
|
| 19 | + $table->string('name'); |
|
| 20 | + $table->string('secret', 100); |
|
| 21 | + $table->text('redirect'); |
|
| 22 | + $table->boolean('personal_access_client')->default(0); |
|
| 23 | + $table->boolean('password_client')->default(0); |
|
| 24 | + $table->boolean('revoked')->default(0); |
|
| 25 | + $table->timestamps(); |
|
| 26 | 26 | |
| 27 | - $table->foreign('user_id')->references('id')->on('users'); |
|
| 28 | - }); |
|
| 29 | - } |
|
| 27 | + $table->foreign('user_id')->references('id')->on('users'); |
|
| 28 | + }); |
|
| 29 | + } |
|
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * Reverse the migrations. |
|
| 33 | - * |
|
| 34 | - * @return void |
|
| 35 | - */ |
|
| 36 | - public function down() |
|
| 37 | - { |
|
| 38 | - Schema::drop('oauth_clients'); |
|
| 39 | - } |
|
| 31 | + /** |
|
| 32 | + * Reverse the migrations. |
|
| 33 | + * |
|
| 34 | + * @return void |
|
| 35 | + */ |
|
| 36 | + public function down() |
|
| 37 | + { |
|
| 38 | + Schema::drop('oauth_clients'); |
|
| 39 | + } |
|
| 40 | 40 | } |
@@ -13,7 +13,7 @@ |
||
| 13 | 13 | */ |
| 14 | 14 | public function up() |
| 15 | 15 | { |
| 16 | - Schema::create('oauth_clients', function (Blueprint $table) { |
|
| 16 | + Schema::create('oauth_clients', function(Blueprint $table) { |
|
| 17 | 17 | increments('id'); |
| 18 | 18 | $table->unsignedInteger('user_id')->nullable(); |
| 19 | 19 | $table->string('name'); |
@@ -8,40 +8,40 @@ |
||
| 8 | 8 | |
| 9 | 9 | class SetSessions |
| 10 | 10 | { |
| 11 | - protected $app; |
|
| 12 | - protected $session; |
|
| 11 | + protected $app; |
|
| 12 | + protected $session; |
|
| 13 | 13 | |
| 14 | - /** |
|
| 15 | - * Init new object. |
|
| 16 | - * |
|
| 17 | - * @param App $app |
|
| 18 | - * @param Session $session |
|
| 19 | - * |
|
| 20 | - * @return void |
|
| 21 | - */ |
|
| 22 | - public function __construct(App $app, Session $session) |
|
| 23 | - { |
|
| 24 | - $this->app = $app; |
|
| 25 | - $this->session = $session; |
|
| 26 | - } |
|
| 14 | + /** |
|
| 15 | + * Init new object. |
|
| 16 | + * |
|
| 17 | + * @param App $app |
|
| 18 | + * @param Session $session |
|
| 19 | + * |
|
| 20 | + * @return void |
|
| 21 | + */ |
|
| 22 | + public function __construct(App $app, Session $session) |
|
| 23 | + { |
|
| 24 | + $this->app = $app; |
|
| 25 | + $this->session = $session; |
|
| 26 | + } |
|
| 27 | 27 | |
| 28 | - /** |
|
| 29 | - * Handle an incoming request. |
|
| 30 | - * |
|
| 31 | - * @param \Illuminate\Http\Request $request |
|
| 32 | - * @param \Closure $next |
|
| 33 | - * @return mixed |
|
| 34 | - */ |
|
| 35 | - public function handle($request, Closure $next) |
|
| 36 | - { |
|
| 37 | - $locale = $request->header('Accept-Language', 'en'); |
|
| 38 | - $locale = $locale == 'ar' || $locale == 'all' ? $locale : 'en'; |
|
| 39 | - $timeZone = $request->header('time-zone', 0); |
|
| 28 | + /** |
|
| 29 | + * Handle an incoming request. |
|
| 30 | + * |
|
| 31 | + * @param \Illuminate\Http\Request $request |
|
| 32 | + * @param \Closure $next |
|
| 33 | + * @return mixed |
|
| 34 | + */ |
|
| 35 | + public function handle($request, Closure $next) |
|
| 36 | + { |
|
| 37 | + $locale = $request->header('Accept-Language', 'en'); |
|
| 38 | + $locale = $locale == 'ar' || $locale == 'all' ? $locale : 'en'; |
|
| 39 | + $timeZone = $request->header('time-zone', 0); |
|
| 40 | 40 | |
| 41 | - $this->session->put('time-zone', $timeZone); |
|
| 42 | - $this->session->put('locale', $locale); |
|
| 43 | - $this->app->setLocale($locale); |
|
| 41 | + $this->session->put('time-zone', $timeZone); |
|
| 42 | + $this->session->put('locale', $locale); |
|
| 43 | + $this->app->setLocale($locale); |
|
| 44 | 44 | |
| 45 | - return $next($request); |
|
| 46 | - } |
|
| 45 | + return $next($request); |
|
| 46 | + } |
|
| 47 | 47 | } |
@@ -8,39 +8,39 @@ |
||
| 8 | 8 | |
| 9 | 9 | class SetRelations |
| 10 | 10 | { |
| 11 | - protected $arr; |
|
| 12 | - protected $route; |
|
| 11 | + protected $arr; |
|
| 12 | + protected $route; |
|
| 13 | 13 | |
| 14 | - /** |
|
| 15 | - * Init new object. |
|
| 16 | - * |
|
| 17 | - * @param Route $route |
|
| 18 | - * @param Arr $arr |
|
| 19 | - * |
|
| 20 | - * @return void |
|
| 21 | - */ |
|
| 22 | - public function __construct(Route $route, Arr $arr) |
|
| 23 | - { |
|
| 24 | - $this->arr = $arr; |
|
| 25 | - $this->route = $route; |
|
| 26 | - } |
|
| 14 | + /** |
|
| 15 | + * Init new object. |
|
| 16 | + * |
|
| 17 | + * @param Route $route |
|
| 18 | + * @param Arr $arr |
|
| 19 | + * |
|
| 20 | + * @return void |
|
| 21 | + */ |
|
| 22 | + public function __construct(Route $route, Arr $arr) |
|
| 23 | + { |
|
| 24 | + $this->arr = $arr; |
|
| 25 | + $this->route = $route; |
|
| 26 | + } |
|
| 27 | 27 | |
| 28 | - /** |
|
| 29 | - * Handle an incoming request. |
|
| 30 | - * |
|
| 31 | - * @param \Illuminate\Http\Request $request |
|
| 32 | - * @param \Closure $next |
|
| 33 | - * @return mixed |
|
| 34 | - */ |
|
| 35 | - public function handle($request, Closure $next) |
|
| 36 | - { |
|
| 37 | - $routeActions = explode('@', $this->route->currentRouteAction()); |
|
| 38 | - $modelName = explode('\\', $routeActions[0]); |
|
| 39 | - $modelName = lcfirst(str_replace('Controller', '', end($modelName))); |
|
| 40 | - $route = explode('@', $this->route->currentRouteAction())[1]; |
|
| 41 | - $relations = $this->arr->get(config('core.relations'), $modelName, false); |
|
| 42 | - $request->relations = $relations && isset($relations[$route]) ? $relations[$route] : []; |
|
| 28 | + /** |
|
| 29 | + * Handle an incoming request. |
|
| 30 | + * |
|
| 31 | + * @param \Illuminate\Http\Request $request |
|
| 32 | + * @param \Closure $next |
|
| 33 | + * @return mixed |
|
| 34 | + */ |
|
| 35 | + public function handle($request, Closure $next) |
|
| 36 | + { |
|
| 37 | + $routeActions = explode('@', $this->route->currentRouteAction()); |
|
| 38 | + $modelName = explode('\\', $routeActions[0]); |
|
| 39 | + $modelName = lcfirst(str_replace('Controller', '', end($modelName))); |
|
| 40 | + $route = explode('@', $this->route->currentRouteAction())[1]; |
|
| 41 | + $relations = $this->arr->get(config('core.relations'), $modelName, false); |
|
| 42 | + $request->relations = $relations && isset($relations[$route]) ? $relations[$route] : []; |
|
| 43 | 43 | |
| 44 | - return $next($request); |
|
| 45 | - } |
|
| 44 | + return $next($request); |
|
| 45 | + } |
|
| 46 | 46 | } |
@@ -11,68 +11,68 @@ |
||
| 11 | 11 | |
| 12 | 12 | class CheckPermissions |
| 13 | 13 | { |
| 14 | - protected $route; |
|
| 15 | - protected $auth; |
|
| 16 | - protected $authMiddleware; |
|
| 17 | - protected $userService; |
|
| 18 | - protected $arr; |
|
| 14 | + protected $route; |
|
| 15 | + protected $auth; |
|
| 16 | + protected $authMiddleware; |
|
| 17 | + protected $userService; |
|
| 18 | + protected $arr; |
|
| 19 | 19 | |
| 20 | - /** |
|
| 21 | - * Init new object. |
|
| 22 | - * |
|
| 23 | - * @param Route $route |
|
| 24 | - * @param Auth $auth |
|
| 25 | - * @param AuthMiddleware $authMiddleware |
|
| 26 | - * @param UserService $userService |
|
| 27 | - * @param Arr $arr |
|
| 28 | - * |
|
| 29 | - * @return void |
|
| 30 | - */ |
|
| 31 | - public function __construct(Route $route, Auth $auth, AuthMiddleware $authMiddleware, UserService $userService, Arr $arr) |
|
| 32 | - { |
|
| 33 | - $this->route = $route; |
|
| 34 | - $this->auth = $auth; |
|
| 35 | - $this->authMiddleware = $authMiddleware; |
|
| 36 | - $this->userService = $userService; |
|
| 37 | - $this->arr = $arr; |
|
| 38 | - } |
|
| 20 | + /** |
|
| 21 | + * Init new object. |
|
| 22 | + * |
|
| 23 | + * @param Route $route |
|
| 24 | + * @param Auth $auth |
|
| 25 | + * @param AuthMiddleware $authMiddleware |
|
| 26 | + * @param UserService $userService |
|
| 27 | + * @param Arr $arr |
|
| 28 | + * |
|
| 29 | + * @return void |
|
| 30 | + */ |
|
| 31 | + public function __construct(Route $route, Auth $auth, AuthMiddleware $authMiddleware, UserService $userService, Arr $arr) |
|
| 32 | + { |
|
| 33 | + $this->route = $route; |
|
| 34 | + $this->auth = $auth; |
|
| 35 | + $this->authMiddleware = $authMiddleware; |
|
| 36 | + $this->userService = $userService; |
|
| 37 | + $this->arr = $arr; |
|
| 38 | + } |
|
| 39 | 39 | |
| 40 | - /** |
|
| 41 | - * Handle an incoming request. |
|
| 42 | - * |
|
| 43 | - * @param \Illuminate\Http\Request $request |
|
| 44 | - * @param \Closure $next |
|
| 45 | - * @return mixed |
|
| 46 | - */ |
|
| 47 | - public function handle($request, Closure $next) |
|
| 48 | - { |
|
| 49 | - $routeActions = explode('@', $this->route->currentRouteAction()); |
|
| 50 | - $reflectionClass = new \ReflectionClass($routeActions[0]); |
|
| 51 | - $classProperties = $reflectionClass->getDefaultProperties(); |
|
| 52 | - $skipPermissionCheck = $this->arr->get($classProperties, 'skipPermissionCheck', []); |
|
| 53 | - $skipLoginCheck = $this->arr->get($classProperties, 'skipLoginCheck', []); |
|
| 54 | - $modelName = explode('\\', $routeActions[0]); |
|
| 55 | - $modelName = lcfirst(str_replace('Controller', '', end($modelName))); |
|
| 56 | - $permission = $routeActions[1]; |
|
| 40 | + /** |
|
| 41 | + * Handle an incoming request. |
|
| 42 | + * |
|
| 43 | + * @param \Illuminate\Http\Request $request |
|
| 44 | + * @param \Closure $next |
|
| 45 | + * @return mixed |
|
| 46 | + */ |
|
| 47 | + public function handle($request, Closure $next) |
|
| 48 | + { |
|
| 49 | + $routeActions = explode('@', $this->route->currentRouteAction()); |
|
| 50 | + $reflectionClass = new \ReflectionClass($routeActions[0]); |
|
| 51 | + $classProperties = $reflectionClass->getDefaultProperties(); |
|
| 52 | + $skipPermissionCheck = $this->arr->get($classProperties, 'skipPermissionCheck', []); |
|
| 53 | + $skipLoginCheck = $this->arr->get($classProperties, 'skipLoginCheck', []); |
|
| 54 | + $modelName = explode('\\', $routeActions[0]); |
|
| 55 | + $modelName = lcfirst(str_replace('Controller', '', end($modelName))); |
|
| 56 | + $permission = $routeActions[1]; |
|
| 57 | 57 | |
| 58 | - $this->auth->shouldUse('api'); |
|
| 59 | - if (! in_array($permission, $skipLoginCheck)) { |
|
| 60 | - $this->authMiddleware->handle($request, function ($request) use ($modelName, $skipPermissionCheck, $permission) { |
|
| 61 | - $user = $this->auth->user(); |
|
| 62 | - $isPasswordClient = $user->token()->client->password_client; |
|
| 58 | + $this->auth->shouldUse('api'); |
|
| 59 | + if (! in_array($permission, $skipLoginCheck)) { |
|
| 60 | + $this->authMiddleware->handle($request, function ($request) use ($modelName, $skipPermissionCheck, $permission) { |
|
| 61 | + $user = $this->auth->user(); |
|
| 62 | + $isPasswordClient = $user->token()->client->password_client; |
|
| 63 | 63 | |
| 64 | - if ($user->blocked) { |
|
| 65 | - \Errors::userIsBlocked(); |
|
| 66 | - } |
|
| 64 | + if ($user->blocked) { |
|
| 65 | + \Errors::userIsBlocked(); |
|
| 66 | + } |
|
| 67 | 67 | |
| 68 | - if ($isPasswordClient && (in_array($permission, $skipPermissionCheck) || $this->userService->can($permission, $modelName))) { |
|
| 69 | - } elseif (! $isPasswordClient && $user->tokenCan($modelName.'-'.$permission)) { |
|
| 70 | - } else { |
|
| 71 | - \Errors::noPermissions(); |
|
| 72 | - } |
|
| 73 | - }); |
|
| 74 | - } |
|
| 68 | + if ($isPasswordClient && (in_array($permission, $skipPermissionCheck) || $this->userService->can($permission, $modelName))) { |
|
| 69 | + } elseif (! $isPasswordClient && $user->tokenCan($modelName.'-'.$permission)) { |
|
| 70 | + } else { |
|
| 71 | + \Errors::noPermissions(); |
|
| 72 | + } |
|
| 73 | + }); |
|
| 74 | + } |
|
| 75 | 75 | |
| 76 | - return $next($request); |
|
| 77 | - } |
|
| 76 | + return $next($request); |
|
| 77 | + } |
|
| 78 | 78 | } |
@@ -56,8 +56,8 @@ discard block |
||
| 56 | 56 | $permission = $routeActions[1]; |
| 57 | 57 | |
| 58 | 58 | $this->auth->shouldUse('api'); |
| 59 | - if (! in_array($permission, $skipLoginCheck)) { |
|
| 60 | - $this->authMiddleware->handle($request, function ($request) use ($modelName, $skipPermissionCheck, $permission) { |
|
| 59 | + if ( ! in_array($permission, $skipLoginCheck)) { |
|
| 60 | + $this->authMiddleware->handle($request, function($request) use ($modelName, $skipPermissionCheck, $permission) { |
|
| 61 | 61 | $user = $this->auth->user(); |
| 62 | 62 | $isPasswordClient = $user->token()->client->password_client; |
| 63 | 63 | |
@@ -66,7 +66,7 @@ discard block |
||
| 66 | 66 | } |
| 67 | 67 | |
| 68 | 68 | if ($isPasswordClient && (in_array($permission, $skipPermissionCheck) || $this->userService->can($permission, $modelName))) { |
| 69 | - } elseif (! $isPasswordClient && $user->tokenCan($modelName.'-'.$permission)) { |
|
| 69 | + } elseif ( ! $isPasswordClient && $user->tokenCan($modelName.'-'.$permission)) { |
|
| 70 | 70 | } else { |
| 71 | 71 | \Errors::noPermissions(); |
| 72 | 72 | } |
@@ -2,15 +2,15 @@ |
||
| 2 | 2 | |
| 3 | 3 | return [ |
| 4 | 4 | |
| 5 | - /** |
|
| 6 | - * Here goes your error messages. |
|
| 7 | - */ |
|
| 8 | - 'connectionError' => 'Connection error', |
|
| 9 | - 'redisNotRunning' => 'Your redis notification server is\'t running', |
|
| 10 | - 'dbQueryError' => 'Please check the given inputes', |
|
| 11 | - 'cannotCreateSetting' => 'Can\'t create setting', |
|
| 12 | - 'cannotUpdateSettingKey' => 'Can\'t update setting key', |
|
| 13 | - 'notFound' => 'The requested :replace not found', |
|
| 14 | - 'cannotUploadImage' => 'Can\'t upload the given image' |
|
| 5 | + /** |
|
| 6 | + * Here goes your error messages. |
|
| 7 | + */ |
|
| 8 | + 'connectionError' => 'Connection error', |
|
| 9 | + 'redisNotRunning' => 'Your redis notification server is\'t running', |
|
| 10 | + 'dbQueryError' => 'Please check the given inputes', |
|
| 11 | + 'cannotCreateSetting' => 'Can\'t create setting', |
|
| 12 | + 'cannotUpdateSettingKey' => 'Can\'t update setting key', |
|
| 13 | + 'notFound' => 'The requested :replace not found', |
|
| 14 | + 'cannotUploadImage' => 'Can\'t upload the given image' |
|
| 15 | 15 | |
| 16 | 16 | ]; |
@@ -2,15 +2,15 @@ |
||
| 2 | 2 | |
| 3 | 3 | return [ |
| 4 | 4 | |
| 5 | - /** |
|
| 6 | - * Here goes your error messages. |
|
| 7 | - */ |
|
| 8 | - 'connectionError' => 'خطأ في الاتصال', |
|
| 9 | - 'redisNotRunning' => 'سيرفير الاشعارات لايعمل', |
|
| 10 | - 'dbQueryError' => 'خطا في البيانات', |
|
| 11 | - 'cannotCreateSetting' => 'لا يمكن اضافة اعدادات', |
|
| 12 | - 'cannotUpdateSettingKey' => 'لا يمكن تعديل اعدادات', |
|
| 13 | - 'notFound' => 'ال :replace المطلوب غير موجود', |
|
| 14 | - 'cannotUploadImage' => 'لا يمكن رفع هذه الصورة' |
|
| 5 | + /** |
|
| 6 | + * Here goes your error messages. |
|
| 7 | + */ |
|
| 8 | + 'connectionError' => 'خطأ في الاتصال', |
|
| 9 | + 'redisNotRunning' => 'سيرفير الاشعارات لايعمل', |
|
| 10 | + 'dbQueryError' => 'خطا في البيانات', |
|
| 11 | + 'cannotCreateSetting' => 'لا يمكن اضافة اعدادات', |
|
| 12 | + 'cannotUpdateSettingKey' => 'لا يمكن تعديل اعدادات', |
|
| 13 | + 'notFound' => 'ال :replace المطلوب غير موجود', |
|
| 14 | + 'cannotUploadImage' => 'لا يمكن رفع هذه الصورة' |
|
| 15 | 15 | |
| 16 | 16 | ]; |
@@ -9,21 +9,21 @@ |
||
| 9 | 9 | class Setting extends Model |
| 10 | 10 | { |
| 11 | 11 | |
| 12 | - use SoftDeletes; |
|
| 13 | - protected $table = 'settings'; |
|
| 14 | - protected $dates = ['created_at', 'updated_at', 'deleted_at']; |
|
| 15 | - protected $hidden = ['deleted_at']; |
|
| 16 | - protected $guarded = ['id', 'key']; |
|
| 17 | - public $fillable = ['name', 'value']; |
|
| 12 | + use SoftDeletes; |
|
| 13 | + protected $table = 'settings'; |
|
| 14 | + protected $dates = ['created_at', 'updated_at', 'deleted_at']; |
|
| 15 | + protected $hidden = ['deleted_at']; |
|
| 16 | + protected $guarded = ['id', 'key']; |
|
| 17 | + public $fillable = ['name', 'value']; |
|
| 18 | 18 | |
| 19 | - public function newCollection(array $models = []) |
|
| 20 | - { |
|
| 21 | - return parent::newCollection($models)->keyBy('key'); |
|
| 22 | - } |
|
| 19 | + public function newCollection(array $models = []) |
|
| 20 | + { |
|
| 21 | + return parent::newCollection($models)->keyBy('key'); |
|
| 22 | + } |
|
| 23 | 23 | |
| 24 | - public static function boot() |
|
| 25 | - { |
|
| 26 | - parent::boot(); |
|
| 27 | - Setting::observe(SettingsObserver::class); |
|
| 28 | - } |
|
| 24 | + public static function boot() |
|
| 25 | + { |
|
| 26 | + parent::boot(); |
|
| 27 | + Setting::observe(SettingsObserver::class); |
|
| 28 | + } |
|
| 29 | 29 | } |
@@ -9,109 +9,109 @@ |
||
| 9 | 9 | |
| 10 | 10 | class BaseApiController extends Controller |
| 11 | 11 | { |
| 12 | - /** |
|
| 13 | - * Array of eager loaded relations. |
|
| 14 | - * |
|
| 15 | - * @var array |
|
| 16 | - */ |
|
| 17 | - protected $relations; |
|
| 12 | + /** |
|
| 13 | + * Array of eager loaded relations. |
|
| 14 | + * |
|
| 15 | + * @var array |
|
| 16 | + */ |
|
| 17 | + protected $relations; |
|
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * @var object |
|
| 21 | - */ |
|
| 22 | - protected $service; |
|
| 19 | + /** |
|
| 20 | + * @var object |
|
| 21 | + */ |
|
| 22 | + protected $service; |
|
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * Path of the model resource. |
|
| 26 | - * |
|
| 27 | - * @var string |
|
| 28 | - */ |
|
| 29 | - protected $modelResource; |
|
| 24 | + /** |
|
| 25 | + * Path of the model resource. |
|
| 26 | + * |
|
| 27 | + * @var string |
|
| 28 | + */ |
|
| 29 | + protected $modelResource; |
|
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * Path of the sotre form request. |
|
| 33 | - * |
|
| 34 | - * @var string |
|
| 35 | - */ |
|
| 36 | - protected $storeFormRequest; |
|
| 31 | + /** |
|
| 32 | + * Path of the sotre form request. |
|
| 33 | + * |
|
| 34 | + * @var string |
|
| 35 | + */ |
|
| 36 | + protected $storeFormRequest; |
|
| 37 | 37 | |
| 38 | - /** |
|
| 39 | - * Init new object. |
|
| 40 | - * |
|
| 41 | - * @param mixed $service |
|
| 42 | - * @return void |
|
| 43 | - */ |
|
| 44 | - public function __construct($service) |
|
| 45 | - { |
|
| 46 | - $this->service = new CachingDecorator($service, \App::make('Illuminate\Contracts\Cache\Repository')); |
|
| 47 | - } |
|
| 38 | + /** |
|
| 39 | + * Init new object. |
|
| 40 | + * |
|
| 41 | + * @param mixed $service |
|
| 42 | + * @return void |
|
| 43 | + */ |
|
| 44 | + public function __construct($service) |
|
| 45 | + { |
|
| 46 | + $this->service = new CachingDecorator($service, \App::make('Illuminate\Contracts\Cache\Repository')); |
|
| 47 | + } |
|
| 48 | 48 | |
| 49 | - /** |
|
| 50 | - * Fetch all records with relations from storage. |
|
| 51 | - * |
|
| 52 | - * @param Request $request |
|
| 53 | - * @return \Illuminate\Http\Response |
|
| 54 | - */ |
|
| 55 | - public function index(Request $request) |
|
| 56 | - { |
|
| 57 | - return $this->modelResource::collection($this->service->list($request->relations, $request->query(), $request->query('perPage'), $request->query('sortBy'), $request->query('desc'), $request->query('trashed'))); |
|
| 58 | - } |
|
| 49 | + /** |
|
| 50 | + * Fetch all records with relations from storage. |
|
| 51 | + * |
|
| 52 | + * @param Request $request |
|
| 53 | + * @return \Illuminate\Http\Response |
|
| 54 | + */ |
|
| 55 | + public function index(Request $request) |
|
| 56 | + { |
|
| 57 | + return $this->modelResource::collection($this->service->list($request->relations, $request->query(), $request->query('perPage'), $request->query('sortBy'), $request->query('desc'), $request->query('trashed'))); |
|
| 58 | + } |
|
| 59 | 59 | |
| 60 | - /** |
|
| 61 | - * Fetch the single object with relations from storage. |
|
| 62 | - * |
|
| 63 | - * @param Request $request |
|
| 64 | - * @param integer $id Id of the requested model. |
|
| 65 | - * @return \Illuminate\Http\Response |
|
| 66 | - */ |
|
| 67 | - public function show(Request $request, $id) |
|
| 68 | - { |
|
| 69 | - return new $this->modelResource($this->service->find($id, $request->relations)); |
|
| 70 | - } |
|
| 60 | + /** |
|
| 61 | + * Fetch the single object with relations from storage. |
|
| 62 | + * |
|
| 63 | + * @param Request $request |
|
| 64 | + * @param integer $id Id of the requested model. |
|
| 65 | + * @return \Illuminate\Http\Response |
|
| 66 | + */ |
|
| 67 | + public function show(Request $request, $id) |
|
| 68 | + { |
|
| 69 | + return new $this->modelResource($this->service->find($id, $request->relations)); |
|
| 70 | + } |
|
| 71 | 71 | |
| 72 | - /** |
|
| 73 | - * Insert the given model to storage. |
|
| 74 | - * |
|
| 75 | - * @return \Illuminate\Http\Response |
|
| 76 | - */ |
|
| 77 | - public function store() |
|
| 78 | - { |
|
| 79 | - $data = \App::make($this->storeFormRequest)->validated(); |
|
| 80 | - return new $this->modelResource($this->service->save($data)); |
|
| 81 | - } |
|
| 72 | + /** |
|
| 73 | + * Insert the given model to storage. |
|
| 74 | + * |
|
| 75 | + * @return \Illuminate\Http\Response |
|
| 76 | + */ |
|
| 77 | + public function store() |
|
| 78 | + { |
|
| 79 | + $data = \App::make($this->storeFormRequest)->validated(); |
|
| 80 | + return new $this->modelResource($this->service->save($data)); |
|
| 81 | + } |
|
| 82 | 82 | |
| 83 | - /** |
|
| 84 | - * Update the given model to storage. |
|
| 85 | - * |
|
| 86 | - * @param integer $id |
|
| 87 | - * @return \Illuminate\Http\Response |
|
| 88 | - */ |
|
| 89 | - public function update($id) |
|
| 90 | - { |
|
| 91 | - $data = \App::make($this->storeFormRequest)->validated(); |
|
| 92 | - $data['id'] = $id; |
|
| 93 | - return new $this->modelResource($this->service->save($data)); |
|
| 94 | - } |
|
| 83 | + /** |
|
| 84 | + * Update the given model to storage. |
|
| 85 | + * |
|
| 86 | + * @param integer $id |
|
| 87 | + * @return \Illuminate\Http\Response |
|
| 88 | + */ |
|
| 89 | + public function update($id) |
|
| 90 | + { |
|
| 91 | + $data = \App::make($this->storeFormRequest)->validated(); |
|
| 92 | + $data['id'] = $id; |
|
| 93 | + return new $this->modelResource($this->service->save($data)); |
|
| 94 | + } |
|
| 95 | 95 | |
| 96 | - /** |
|
| 97 | - * Delete by the given id from storage. |
|
| 98 | - * |
|
| 99 | - * @param integer $id Id of the deleted model. |
|
| 100 | - * @return \Illuminate\Http\Response |
|
| 101 | - */ |
|
| 102 | - public function destroy($id) |
|
| 103 | - { |
|
| 104 | - return new GeneralResource($this->service->delete($id)); |
|
| 105 | - } |
|
| 96 | + /** |
|
| 97 | + * Delete by the given id from storage. |
|
| 98 | + * |
|
| 99 | + * @param integer $id Id of the deleted model. |
|
| 100 | + * @return \Illuminate\Http\Response |
|
| 101 | + */ |
|
| 102 | + public function destroy($id) |
|
| 103 | + { |
|
| 104 | + return new GeneralResource($this->service->delete($id)); |
|
| 105 | + } |
|
| 106 | 106 | |
| 107 | - /** |
|
| 108 | - * Restore the deleted model. |
|
| 109 | - * |
|
| 110 | - * @param integer $id Id of the restored model. |
|
| 111 | - * @return \Illuminate\Http\Response |
|
| 112 | - */ |
|
| 113 | - public function restore($id) |
|
| 114 | - { |
|
| 115 | - return new GeneralResource($this->service->restore($id)); |
|
| 116 | - } |
|
| 107 | + /** |
|
| 108 | + * Restore the deleted model. |
|
| 109 | + * |
|
| 110 | + * @param integer $id Id of the restored model. |
|
| 111 | + * @return \Illuminate\Http\Response |
|
| 112 | + */ |
|
| 113 | + public function restore($id) |
|
| 114 | + { |
|
| 115 | + return new GeneralResource($this->service->restore($id)); |
|
| 116 | + } |
|
| 117 | 117 | } |