@@ -1,6 +1,5 @@ |
||
| 1 | 1 | <?php namespace App\Modules\Acl; |
| 2 | 2 | |
| 3 | -use Illuminate\Database\Eloquent\Model; |
|
| 4 | 3 | use App\User; |
| 5 | 4 | use Illuminate\Database\Eloquent\SoftDeletes; |
| 6 | 5 | |
@@ -9,7 +9,7 @@ discard block |
||
| 9 | 9 | use SoftDeletes; |
| 10 | 10 | protected $table = 'users'; |
| 11 | 11 | protected $dates = ['created_at', 'updated_at', 'deleted_at']; |
| 12 | - protected $hidden = ['password', 'remember_token','deleted_at']; |
|
| 12 | + protected $hidden = ['password', 'remember_token', 'deleted_at']; |
|
| 13 | 13 | protected $guarded = ['id']; |
| 14 | 14 | protected $fillable = ['first_name', 'last_name', 'user_name', 'address', 'email', 'password']; |
| 15 | 15 | protected $appends = ['permissions']; |
@@ -47,7 +47,7 @@ discard block |
||
| 47 | 47 | |
| 48 | 48 | public function groups() |
| 49 | 49 | { |
| 50 | - return $this->belongsToMany('\App\Modules\V1\Acl\AclGroup','users_groups','user_id','group_id')->whereNull('users_groups.deleted_at')->withTimestamps(); |
|
| 50 | + return $this->belongsToMany('\App\Modules\V1\Acl\AclGroup', 'users_groups', 'user_id', 'group_id')->whereNull('users_groups.deleted_at')->withTimestamps(); |
|
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | public function getPermissionsAttribute() |
@@ -55,7 +55,7 @@ discard block |
||
| 55 | 55 | $permissions = []; |
| 56 | 56 | foreach ($this->groups as $group) |
| 57 | 57 | { |
| 58 | - $group->permissions->each(function ($permission) use (&$permissions){ |
|
| 58 | + $group->permissions->each(function($permission) use (&$permissions){ |
|
| 59 | 59 | $permissions[$permission->model][$permission->id] = $permission->name; |
| 60 | 60 | }); |
| 61 | 61 | } |
@@ -6,66 +6,66 @@ |
||
| 6 | 6 | |
| 7 | 7 | class AclUser extends User { |
| 8 | 8 | |
| 9 | - use SoftDeletes; |
|
| 10 | - protected $table = 'users'; |
|
| 11 | - protected $dates = ['created_at', 'updated_at', 'deleted_at']; |
|
| 12 | - protected $hidden = ['password', 'remember_token','deleted_at']; |
|
| 13 | - protected $guarded = ['id']; |
|
| 14 | - protected $fillable = ['name', 'email', 'password']; |
|
| 15 | - protected $appends = ['permissions']; |
|
| 9 | + use SoftDeletes; |
|
| 10 | + protected $table = 'users'; |
|
| 11 | + protected $dates = ['created_at', 'updated_at', 'deleted_at']; |
|
| 12 | + protected $hidden = ['password', 'remember_token','deleted_at']; |
|
| 13 | + protected $guarded = ['id']; |
|
| 14 | + protected $fillable = ['name', 'email', 'password']; |
|
| 15 | + protected $appends = ['permissions']; |
|
| 16 | 16 | |
| 17 | - public function getCreatedAtAttribute($value) |
|
| 18 | - { |
|
| 19 | - return \Carbon\Carbon::parse($value)->addHours(\Session::get('timeZoneDiff'))->toDateTimeString(); |
|
| 20 | - } |
|
| 17 | + public function getCreatedAtAttribute($value) |
|
| 18 | + { |
|
| 19 | + return \Carbon\Carbon::parse($value)->addHours(\Session::get('timeZoneDiff'))->toDateTimeString(); |
|
| 20 | + } |
|
| 21 | 21 | |
| 22 | - public function getUpdatedAtAttribute($value) |
|
| 23 | - { |
|
| 24 | - return \Carbon\Carbon::parse($value)->addHours(\Session::get('timeZoneDiff'))->toDateTimeString(); |
|
| 25 | - } |
|
| 22 | + public function getUpdatedAtAttribute($value) |
|
| 23 | + { |
|
| 24 | + return \Carbon\Carbon::parse($value)->addHours(\Session::get('timeZoneDiff'))->toDateTimeString(); |
|
| 25 | + } |
|
| 26 | 26 | |
| 27 | - public function getDeletedAtAttribute($value) |
|
| 28 | - { |
|
| 29 | - return \Carbon\Carbon::parse($value)->addHours(\Session::get('timeZoneDiff'))->toDateTimeString(); |
|
| 30 | - } |
|
| 27 | + public function getDeletedAtAttribute($value) |
|
| 28 | + { |
|
| 29 | + return \Carbon\Carbon::parse($value)->addHours(\Session::get('timeZoneDiff'))->toDateTimeString(); |
|
| 30 | + } |
|
| 31 | 31 | |
| 32 | - /** |
|
| 33 | - * Encrypt the password attribute before |
|
| 34 | - * saving it in the storage. |
|
| 35 | - * |
|
| 36 | - * @param string $value |
|
| 37 | - */ |
|
| 38 | - public function setPasswordAttribute($value) |
|
| 39 | - { |
|
| 40 | - $this->attributes['password'] = bcrypt($value); |
|
| 41 | - } |
|
| 32 | + /** |
|
| 33 | + * Encrypt the password attribute before |
|
| 34 | + * saving it in the storage. |
|
| 35 | + * |
|
| 36 | + * @param string $value |
|
| 37 | + */ |
|
| 38 | + public function setPasswordAttribute($value) |
|
| 39 | + { |
|
| 40 | + $this->attributes['password'] = bcrypt($value); |
|
| 41 | + } |
|
| 42 | 42 | |
| 43 | - public function logs() |
|
| 44 | - { |
|
| 45 | - return $this->hasMany('App\Modules\V1\Logging\Log', 'user_id'); |
|
| 46 | - } |
|
| 43 | + public function logs() |
|
| 44 | + { |
|
| 45 | + return $this->hasMany('App\Modules\V1\Logging\Log', 'user_id'); |
|
| 46 | + } |
|
| 47 | 47 | |
| 48 | - public function groups() |
|
| 49 | - { |
|
| 50 | - return $this->belongsToMany('\App\Modules\V1\Acl\AclGroup','users_groups','user_id','group_id')->whereNull('users_groups.deleted_at')->withTimestamps(); |
|
| 51 | - } |
|
| 48 | + public function groups() |
|
| 49 | + { |
|
| 50 | + return $this->belongsToMany('\App\Modules\V1\Acl\AclGroup','users_groups','user_id','group_id')->whereNull('users_groups.deleted_at')->withTimestamps(); |
|
| 51 | + } |
|
| 52 | 52 | |
| 53 | - public function getPermissionsAttribute() |
|
| 54 | - { |
|
| 55 | - $permissions = []; |
|
| 56 | - foreach ($this->groups as $group) |
|
| 57 | - { |
|
| 58 | - $group->permissions->each(function ($permission) use (&$permissions){ |
|
| 59 | - $permissions[$permission->model][$permission->id] = $permission->name; |
|
| 60 | - }); |
|
| 61 | - } |
|
| 53 | + public function getPermissionsAttribute() |
|
| 54 | + { |
|
| 55 | + $permissions = []; |
|
| 56 | + foreach ($this->groups as $group) |
|
| 57 | + { |
|
| 58 | + $group->permissions->each(function ($permission) use (&$permissions){ |
|
| 59 | + $permissions[$permission->model][$permission->id] = $permission->name; |
|
| 60 | + }); |
|
| 61 | + } |
|
| 62 | 62 | |
| 63 | - return \Illuminate\Database\Eloquent\Collection::make($permissions); |
|
| 64 | - } |
|
| 63 | + return \Illuminate\Database\Eloquent\Collection::make($permissions); |
|
| 64 | + } |
|
| 65 | 65 | |
| 66 | - public static function boot() |
|
| 67 | - { |
|
| 68 | - parent::boot(); |
|
| 69 | - parent::observe(\App::make('App\Modules\V1\Acl\ModelObservers\AclUserObserver')); |
|
| 70 | - } |
|
| 66 | + public static function boot() |
|
| 67 | + { |
|
| 68 | + parent::boot(); |
|
| 69 | + parent::observe(\App::make('App\Modules\V1\Acl\ModelObservers\AclUserObserver')); |
|
| 70 | + } |
|
| 71 | 71 | } |
@@ -54,9 +54,7 @@ discard block |
||
| 54 | 54 | /** |
| 55 | 55 | * Fetch all records with relations from model repository. |
| 56 | 56 | * |
| 57 | - * @param string $sortBy |
|
| 58 | - * @param boolean $desc |
|
| 59 | - * @return \Illuminate\Http\Response |
|
| 57 | + * @return \Illuminate\Http\JsonResponse|null |
|
| 60 | 58 | */ |
| 61 | 59 | public function getIndex() |
| 62 | 60 | { |
@@ -71,7 +69,7 @@ discard block |
||
| 71 | 69 | * Fetch the single object with relations from model repository. |
| 72 | 70 | * |
| 73 | 71 | * @param integer $id |
| 74 | - * @return \Illuminate\Http\Response |
|
| 72 | + * @return \Illuminate\Http\JsonResponse|null |
|
| 75 | 73 | */ |
| 76 | 74 | public function getFind($id) |
| 77 | 75 | { |
@@ -89,8 +87,8 @@ discard block |
||
| 89 | 87 | * @param string $query |
| 90 | 88 | * @param integer $perPage |
| 91 | 89 | * @param string $sortBy |
| 92 | - * @param boolean $desc |
|
| 93 | - * @return \Illuminate\Http\Response |
|
| 90 | + * @param integer $desc |
|
| 91 | + * @return \Illuminate\Http\JsonResponse|null |
|
| 94 | 92 | */ |
| 95 | 93 | public function getSearch($query = '', $perPage = 15, $sortBy = 'created_at', $desc = 1) |
| 96 | 94 | { |
@@ -107,8 +105,8 @@ discard block |
||
| 107 | 105 | * |
| 108 | 106 | * @param \Illuminate\Http\Request $request |
| 109 | 107 | * @param string $sortBy |
| 110 | - * @param boolean $desc |
|
| 111 | - * @return \Illuminate\Http\Response |
|
| 108 | + * @param integer $desc |
|
| 109 | + * @return \Illuminate\Http\JsonResponse|null |
|
| 112 | 110 | */ |
| 113 | 111 | public function postFindby(Request $request, $sortBy = 'created_at', $desc = 1) |
| 114 | 112 | { |
@@ -124,7 +122,7 @@ discard block |
||
| 124 | 122 | * condition. |
| 125 | 123 | * |
| 126 | 124 | * @param \Illuminate\Http\Request $request |
| 127 | - * @return \Illuminate\Http\Response |
|
| 125 | + * @return \Illuminate\Http\JsonResponse|null |
|
| 128 | 126 | */ |
| 129 | 127 | public function postFirst(Request $request) |
| 130 | 128 | { |
@@ -140,8 +138,8 @@ discard block |
||
| 140 | 138 | * |
| 141 | 139 | * @param integer $perPage |
| 142 | 140 | * @param string $sortBy |
| 143 | - * @param boolean $desc |
|
| 144 | - * @return \Illuminate\Http\Response |
|
| 141 | + * @param integer $desc |
|
| 142 | + * @return \Illuminate\Http\JsonResponse|null |
|
| 145 | 143 | */ |
| 146 | 144 | public function getPaginate($perPage = 15, $sortBy = 'created_at', $desc = 1) |
| 147 | 145 | { |
@@ -159,8 +157,8 @@ discard block |
||
| 159 | 157 | * @param \Illuminate\Http\Request $request |
| 160 | 158 | * @param integer $perPage |
| 161 | 159 | * @param string $sortBy |
| 162 | - * @param boolean $desc |
|
| 163 | - * @return \Illuminate\Http\Response |
|
| 160 | + * @param integer $desc |
|
| 161 | + * @return \Illuminate\Http\JsonResponse|null |
|
| 164 | 162 | */ |
| 165 | 163 | public function postPaginateby(Request $request, $perPage = 15, $sortBy = 'created_at', $desc = 1) |
| 166 | 164 | { |
@@ -175,7 +173,7 @@ discard block |
||
| 175 | 173 | * Save the given model to repository. |
| 176 | 174 | * |
| 177 | 175 | * @param \Illuminate\Http\Request $request |
| 178 | - * @return \Illuminate\Http\Response |
|
| 176 | + * @return \Illuminate\Http\JsonResponse|null |
|
| 179 | 177 | */ |
| 180 | 178 | public function postSave(Request $request) |
| 181 | 179 | { |
@@ -208,7 +206,7 @@ discard block |
||
| 208 | 206 | * Delete by the given id from model repository. |
| 209 | 207 | * |
| 210 | 208 | * @param integer $id |
| 211 | - * @return \Illuminate\Http\Response |
|
| 209 | + * @return \Illuminate\Http\JsonResponse|null |
|
| 212 | 210 | */ |
| 213 | 211 | public function getDelete($id) |
| 214 | 212 | { |
@@ -6,221 +6,221 @@ |
||
| 6 | 6 | |
| 7 | 7 | class BaseApiController extends Controller |
| 8 | 8 | { |
| 9 | - /** |
|
| 10 | - * The model implementation. |
|
| 11 | - * |
|
| 12 | - * @var model |
|
| 13 | - */ |
|
| 14 | - protected $model; |
|
| 15 | - |
|
| 16 | - /** |
|
| 17 | - * The config implementation. |
|
| 18 | - * |
|
| 19 | - * @var config |
|
| 20 | - */ |
|
| 21 | - protected $config; |
|
| 22 | - |
|
| 23 | - public function __construct() |
|
| 24 | - { |
|
| 25 | - \Session::set('timeZoneDiff', \Request::header('time-zone-diff') ?: 0); |
|
| 9 | + /** |
|
| 10 | + * The model implementation. |
|
| 11 | + * |
|
| 12 | + * @var model |
|
| 13 | + */ |
|
| 14 | + protected $model; |
|
| 15 | + |
|
| 16 | + /** |
|
| 17 | + * The config implementation. |
|
| 18 | + * |
|
| 19 | + * @var config |
|
| 20 | + */ |
|
| 21 | + protected $config; |
|
| 22 | + |
|
| 23 | + public function __construct() |
|
| 24 | + { |
|
| 25 | + \Session::set('timeZoneDiff', \Request::header('time-zone-diff') ?: 0); |
|
| 26 | 26 | |
| 27 | - $this->config = \CoreConfig::getConfig(); |
|
| 28 | - $this->model = property_exists($this, 'model') ? $this->model : false; |
|
| 29 | - $this->validationRules = property_exists($this, 'validationRules') ? $this->validationRules : false; |
|
| 30 | - $this->skipPermissionCheck = property_exists($this, 'skipPermissionCheck') ? $this->skipPermissionCheck : []; |
|
| 31 | - $this->skipLoginCheck = property_exists($this, 'skipLoginCheck') ? $this->skipLoginCheck : []; |
|
| 32 | - $this->relations = array_key_exists($this->model, $this->config['relations']) ? $this->config['relations'][$this->model] : false; |
|
| 33 | - $route = explode('@',\Route::currentRouteAction())[1]; |
|
| 34 | - $this->checkPermission(explode('_', snake_case($route))[1]); |
|
| 35 | - } |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * Fetch all records with relations from model repository. |
|
| 39 | - * |
|
| 40 | - * @param string $sortBy |
|
| 41 | - * @param boolean $desc |
|
| 42 | - * @return \Illuminate\Http\Response |
|
| 43 | - */ |
|
| 44 | - public function getIndex() |
|
| 45 | - { |
|
| 46 | - if ($this->model) |
|
| 47 | - { |
|
| 48 | - $relations = $this->relations && $this->relations['all'] ? $this->relations['all'] : []; |
|
| 49 | - return \Response::json(call_user_func_array("\Core::{$this->model}", [])->all($relations), 200); |
|
| 50 | - } |
|
| 51 | - } |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * Fetch the single object with relations from model repository. |
|
| 55 | - * |
|
| 56 | - * @param integer $id |
|
| 57 | - * @return \Illuminate\Http\Response |
|
| 58 | - */ |
|
| 59 | - public function getFind($id) |
|
| 60 | - { |
|
| 61 | - if ($this->model) |
|
| 62 | - { |
|
| 63 | - $relations = $this->relations && $this->relations['find'] ? $this->relations['find'] : []; |
|
| 64 | - return \Response::json(call_user_func_array("\Core::{$this->model}", [])->find($id, $relations), 200); |
|
| 65 | - } |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - /** |
|
| 69 | - * Paginate all records with relations from model repository |
|
| 70 | - * that matche the given query. |
|
| 71 | - * |
|
| 72 | - * @param string $query |
|
| 73 | - * @param integer $perPage |
|
| 74 | - * @param string $sortBy |
|
| 75 | - * @param boolean $desc |
|
| 76 | - * @return \Illuminate\Http\Response |
|
| 77 | - */ |
|
| 78 | - public function getSearch($query = '', $perPage = 15, $sortBy = 'created_at', $desc = 1) |
|
| 79 | - { |
|
| 80 | - if ($this->model) |
|
| 81 | - { |
|
| 82 | - $relations = $this->relations && $this->relations['paginate'] ? $this->relations['paginate'] : []; |
|
| 83 | - return \Response::json(call_user_func_array("\Core::{$this->model}", [])->search($query, $perPage, $relations, $sortBy, $desc), 200); |
|
| 84 | - } |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - /** |
|
| 88 | - * Fetch records from the storage based on the given |
|
| 89 | - * condition. |
|
| 90 | - * |
|
| 91 | - * @param \Illuminate\Http\Request $request |
|
| 92 | - * @param string $sortBy |
|
| 93 | - * @param boolean $desc |
|
| 94 | - * @return \Illuminate\Http\Response |
|
| 95 | - */ |
|
| 96 | - public function postFindby(Request $request, $sortBy = 'created_at', $desc = 1) |
|
| 97 | - { |
|
| 98 | - if ($this->model) |
|
| 99 | - { |
|
| 100 | - $relations = $this->relations && $this->relations['findBy'] ? $this->relations['findBy'] : []; |
|
| 101 | - return \Response::json(call_user_func_array("\Core::{$this->model}", [])->findBy($request->all(), $relations, $sortBy, $desc), 200); |
|
| 102 | - } |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - /** |
|
| 106 | - * Fetch the first record from the storage based on the given |
|
| 107 | - * condition. |
|
| 108 | - * |
|
| 109 | - * @param \Illuminate\Http\Request $request |
|
| 110 | - * @return \Illuminate\Http\Response |
|
| 111 | - */ |
|
| 112 | - public function postFirst(Request $request) |
|
| 113 | - { |
|
| 114 | - if ($this->model) |
|
| 115 | - { |
|
| 116 | - $relations = $this->relations && $this->relations['first'] ? $this->relations['first'] : []; |
|
| 117 | - return \Response::json(call_user_func_array("\Core::{$this->model}", [])->first($request->all(), $relations), 200); |
|
| 118 | - } |
|
| 119 | - } |
|
| 120 | - |
|
| 121 | - /** |
|
| 122 | - * Paginate all records with relations from model repository. |
|
| 123 | - * |
|
| 124 | - * @param integer $perPage |
|
| 125 | - * @param string $sortBy |
|
| 126 | - * @param boolean $desc |
|
| 127 | - * @return \Illuminate\Http\Response |
|
| 128 | - */ |
|
| 129 | - public function getPaginate($perPage = 15, $sortBy = 'created_at', $desc = 1) |
|
| 130 | - { |
|
| 131 | - if ($this->model) |
|
| 132 | - { |
|
| 133 | - $relations = $this->relations && $this->relations['paginate'] ? $this->relations['paginate'] : []; |
|
| 134 | - return \Response::json(call_user_func_array("\Core::{$this->model}", [])->paginate($perPage, $relations, $sortBy, $desc), 200); |
|
| 135 | - } |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - /** |
|
| 139 | - * Fetch all records with relations based on |
|
| 140 | - * the given condition from storage in pages. |
|
| 141 | - * |
|
| 142 | - * @param \Illuminate\Http\Request $request |
|
| 143 | - * @param integer $perPage |
|
| 144 | - * @param string $sortBy |
|
| 145 | - * @param boolean $desc |
|
| 146 | - * @return \Illuminate\Http\Response |
|
| 147 | - */ |
|
| 148 | - public function postPaginateby(Request $request, $perPage = 15, $sortBy = 'created_at', $desc = 1) |
|
| 149 | - { |
|
| 150 | - if ($this->model) |
|
| 151 | - { |
|
| 152 | - $relations = $this->relations && $this->relations['paginateBy'] ? $this->relations['paginateBy'] : []; |
|
| 153 | - return \Response::json(call_user_func_array("\Core::{$this->model}", [])->paginateBy($request->all(), $perPage, $relations, $sortBy, $desc), 200); |
|
| 154 | - } |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - /** |
|
| 158 | - * Save the given model to repository. |
|
| 159 | - * |
|
| 160 | - * @param \Illuminate\Http\Request $request |
|
| 161 | - * @return \Illuminate\Http\Response |
|
| 162 | - */ |
|
| 163 | - public function postSave(Request $request) |
|
| 164 | - { |
|
| 165 | - foreach ($this->validationRules as &$rule) |
|
| 166 | - { |
|
| 167 | - if (strpos($rule, 'exists') && ! strpos($rule, 'deleted_at,NULL')) |
|
| 168 | - { |
|
| 169 | - $rule .= ',deleted_at,NULL'; |
|
| 170 | - } |
|
| 171 | - |
|
| 172 | - if ($request->has('id')) |
|
| 173 | - { |
|
| 174 | - $rule = str_replace('{id}', $request->get('id'), $rule); |
|
| 175 | - } |
|
| 176 | - else |
|
| 177 | - { |
|
| 178 | - $rule = str_replace(',{id}', '', $rule); |
|
| 179 | - } |
|
| 180 | - } |
|
| 27 | + $this->config = \CoreConfig::getConfig(); |
|
| 28 | + $this->model = property_exists($this, 'model') ? $this->model : false; |
|
| 29 | + $this->validationRules = property_exists($this, 'validationRules') ? $this->validationRules : false; |
|
| 30 | + $this->skipPermissionCheck = property_exists($this, 'skipPermissionCheck') ? $this->skipPermissionCheck : []; |
|
| 31 | + $this->skipLoginCheck = property_exists($this, 'skipLoginCheck') ? $this->skipLoginCheck : []; |
|
| 32 | + $this->relations = array_key_exists($this->model, $this->config['relations']) ? $this->config['relations'][$this->model] : false; |
|
| 33 | + $route = explode('@',\Route::currentRouteAction())[1]; |
|
| 34 | + $this->checkPermission(explode('_', snake_case($route))[1]); |
|
| 35 | + } |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * Fetch all records with relations from model repository. |
|
| 39 | + * |
|
| 40 | + * @param string $sortBy |
|
| 41 | + * @param boolean $desc |
|
| 42 | + * @return \Illuminate\Http\Response |
|
| 43 | + */ |
|
| 44 | + public function getIndex() |
|
| 45 | + { |
|
| 46 | + if ($this->model) |
|
| 47 | + { |
|
| 48 | + $relations = $this->relations && $this->relations['all'] ? $this->relations['all'] : []; |
|
| 49 | + return \Response::json(call_user_func_array("\Core::{$this->model}", [])->all($relations), 200); |
|
| 50 | + } |
|
| 51 | + } |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + * Fetch the single object with relations from model repository. |
|
| 55 | + * |
|
| 56 | + * @param integer $id |
|
| 57 | + * @return \Illuminate\Http\Response |
|
| 58 | + */ |
|
| 59 | + public function getFind($id) |
|
| 60 | + { |
|
| 61 | + if ($this->model) |
|
| 62 | + { |
|
| 63 | + $relations = $this->relations && $this->relations['find'] ? $this->relations['find'] : []; |
|
| 64 | + return \Response::json(call_user_func_array("\Core::{$this->model}", [])->find($id, $relations), 200); |
|
| 65 | + } |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + /** |
|
| 69 | + * Paginate all records with relations from model repository |
|
| 70 | + * that matche the given query. |
|
| 71 | + * |
|
| 72 | + * @param string $query |
|
| 73 | + * @param integer $perPage |
|
| 74 | + * @param string $sortBy |
|
| 75 | + * @param boolean $desc |
|
| 76 | + * @return \Illuminate\Http\Response |
|
| 77 | + */ |
|
| 78 | + public function getSearch($query = '', $perPage = 15, $sortBy = 'created_at', $desc = 1) |
|
| 79 | + { |
|
| 80 | + if ($this->model) |
|
| 81 | + { |
|
| 82 | + $relations = $this->relations && $this->relations['paginate'] ? $this->relations['paginate'] : []; |
|
| 83 | + return \Response::json(call_user_func_array("\Core::{$this->model}", [])->search($query, $perPage, $relations, $sortBy, $desc), 200); |
|
| 84 | + } |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + /** |
|
| 88 | + * Fetch records from the storage based on the given |
|
| 89 | + * condition. |
|
| 90 | + * |
|
| 91 | + * @param \Illuminate\Http\Request $request |
|
| 92 | + * @param string $sortBy |
|
| 93 | + * @param boolean $desc |
|
| 94 | + * @return \Illuminate\Http\Response |
|
| 95 | + */ |
|
| 96 | + public function postFindby(Request $request, $sortBy = 'created_at', $desc = 1) |
|
| 97 | + { |
|
| 98 | + if ($this->model) |
|
| 99 | + { |
|
| 100 | + $relations = $this->relations && $this->relations['findBy'] ? $this->relations['findBy'] : []; |
|
| 101 | + return \Response::json(call_user_func_array("\Core::{$this->model}", [])->findBy($request->all(), $relations, $sortBy, $desc), 200); |
|
| 102 | + } |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + /** |
|
| 106 | + * Fetch the first record from the storage based on the given |
|
| 107 | + * condition. |
|
| 108 | + * |
|
| 109 | + * @param \Illuminate\Http\Request $request |
|
| 110 | + * @return \Illuminate\Http\Response |
|
| 111 | + */ |
|
| 112 | + public function postFirst(Request $request) |
|
| 113 | + { |
|
| 114 | + if ($this->model) |
|
| 115 | + { |
|
| 116 | + $relations = $this->relations && $this->relations['first'] ? $this->relations['first'] : []; |
|
| 117 | + return \Response::json(call_user_func_array("\Core::{$this->model}", [])->first($request->all(), $relations), 200); |
|
| 118 | + } |
|
| 119 | + } |
|
| 120 | + |
|
| 121 | + /** |
|
| 122 | + * Paginate all records with relations from model repository. |
|
| 123 | + * |
|
| 124 | + * @param integer $perPage |
|
| 125 | + * @param string $sortBy |
|
| 126 | + * @param boolean $desc |
|
| 127 | + * @return \Illuminate\Http\Response |
|
| 128 | + */ |
|
| 129 | + public function getPaginate($perPage = 15, $sortBy = 'created_at', $desc = 1) |
|
| 130 | + { |
|
| 131 | + if ($this->model) |
|
| 132 | + { |
|
| 133 | + $relations = $this->relations && $this->relations['paginate'] ? $this->relations['paginate'] : []; |
|
| 134 | + return \Response::json(call_user_func_array("\Core::{$this->model}", [])->paginate($perPage, $relations, $sortBy, $desc), 200); |
|
| 135 | + } |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + /** |
|
| 139 | + * Fetch all records with relations based on |
|
| 140 | + * the given condition from storage in pages. |
|
| 141 | + * |
|
| 142 | + * @param \Illuminate\Http\Request $request |
|
| 143 | + * @param integer $perPage |
|
| 144 | + * @param string $sortBy |
|
| 145 | + * @param boolean $desc |
|
| 146 | + * @return \Illuminate\Http\Response |
|
| 147 | + */ |
|
| 148 | + public function postPaginateby(Request $request, $perPage = 15, $sortBy = 'created_at', $desc = 1) |
|
| 149 | + { |
|
| 150 | + if ($this->model) |
|
| 151 | + { |
|
| 152 | + $relations = $this->relations && $this->relations['paginateBy'] ? $this->relations['paginateBy'] : []; |
|
| 153 | + return \Response::json(call_user_func_array("\Core::{$this->model}", [])->paginateBy($request->all(), $perPage, $relations, $sortBy, $desc), 200); |
|
| 154 | + } |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + /** |
|
| 158 | + * Save the given model to repository. |
|
| 159 | + * |
|
| 160 | + * @param \Illuminate\Http\Request $request |
|
| 161 | + * @return \Illuminate\Http\Response |
|
| 162 | + */ |
|
| 163 | + public function postSave(Request $request) |
|
| 164 | + { |
|
| 165 | + foreach ($this->validationRules as &$rule) |
|
| 166 | + { |
|
| 167 | + if (strpos($rule, 'exists') && ! strpos($rule, 'deleted_at,NULL')) |
|
| 168 | + { |
|
| 169 | + $rule .= ',deleted_at,NULL'; |
|
| 170 | + } |
|
| 171 | + |
|
| 172 | + if ($request->has('id')) |
|
| 173 | + { |
|
| 174 | + $rule = str_replace('{id}', $request->get('id'), $rule); |
|
| 175 | + } |
|
| 176 | + else |
|
| 177 | + { |
|
| 178 | + $rule = str_replace(',{id}', '', $rule); |
|
| 179 | + } |
|
| 180 | + } |
|
| 181 | 181 | |
| 182 | - $this->validate($request, $this->validationRules); |
|
| 183 | - |
|
| 184 | - if ($this->model) |
|
| 185 | - { |
|
| 186 | - return \Response::json(call_user_func_array("\Core::{$this->model}", [])->save($request->all()), 200); |
|
| 187 | - } |
|
| 188 | - } |
|
| 189 | - |
|
| 190 | - /** |
|
| 191 | - * Delete by the given id from model repository. |
|
| 192 | - * |
|
| 193 | - * @param integer $id |
|
| 194 | - * @return \Illuminate\Http\Response |
|
| 195 | - */ |
|
| 196 | - public function getDelete($id) |
|
| 197 | - { |
|
| 198 | - if ($this->model) |
|
| 199 | - { |
|
| 200 | - return \Response::json(call_user_func_array("\Core::{$this->model}", [])->delete($id), 200); |
|
| 201 | - } |
|
| 202 | - } |
|
| 203 | - |
|
| 204 | - /** |
|
| 205 | - * Check if the logged in user can do the given permission. |
|
| 206 | - * |
|
| 207 | - * @param string $permission |
|
| 208 | - * @return void |
|
| 209 | - */ |
|
| 210 | - private function checkPermission($permission) |
|
| 211 | - { |
|
| 212 | - $permission = $permission !== 'index' ? $permission : 'list'; |
|
| 213 | - if ($permission == 'method') |
|
| 214 | - { |
|
| 215 | - \ErrorHandler::notFound('method'); |
|
| 216 | - } |
|
| 217 | - else if ( ! in_array($permission, $this->skipLoginCheck)) |
|
| 218 | - { |
|
| 219 | - \JWTAuth::parseToken()->authenticate(); |
|
| 220 | - if ( ! in_array($permission, $this->skipPermissionCheck) && ! \Core::users()->can($permission, $this->model)) |
|
| 221 | - { |
|
| 222 | - \ErrorHandler::noPermissions(); |
|
| 223 | - } |
|
| 224 | - } |
|
| 225 | - } |
|
| 182 | + $this->validate($request, $this->validationRules); |
|
| 183 | + |
|
| 184 | + if ($this->model) |
|
| 185 | + { |
|
| 186 | + return \Response::json(call_user_func_array("\Core::{$this->model}", [])->save($request->all()), 200); |
|
| 187 | + } |
|
| 188 | + } |
|
| 189 | + |
|
| 190 | + /** |
|
| 191 | + * Delete by the given id from model repository. |
|
| 192 | + * |
|
| 193 | + * @param integer $id |
|
| 194 | + * @return \Illuminate\Http\Response |
|
| 195 | + */ |
|
| 196 | + public function getDelete($id) |
|
| 197 | + { |
|
| 198 | + if ($this->model) |
|
| 199 | + { |
|
| 200 | + return \Response::json(call_user_func_array("\Core::{$this->model}", [])->delete($id), 200); |
|
| 201 | + } |
|
| 202 | + } |
|
| 203 | + |
|
| 204 | + /** |
|
| 205 | + * Check if the logged in user can do the given permission. |
|
| 206 | + * |
|
| 207 | + * @param string $permission |
|
| 208 | + * @return void |
|
| 209 | + */ |
|
| 210 | + private function checkPermission($permission) |
|
| 211 | + { |
|
| 212 | + $permission = $permission !== 'index' ? $permission : 'list'; |
|
| 213 | + if ($permission == 'method') |
|
| 214 | + { |
|
| 215 | + \ErrorHandler::notFound('method'); |
|
| 216 | + } |
|
| 217 | + else if ( ! in_array($permission, $this->skipLoginCheck)) |
|
| 218 | + { |
|
| 219 | + \JWTAuth::parseToken()->authenticate(); |
|
| 220 | + if ( ! in_array($permission, $this->skipPermissionCheck) && ! \Core::users()->can($permission, $this->model)) |
|
| 221 | + { |
|
| 222 | + \ErrorHandler::noPermissions(); |
|
| 223 | + } |
|
| 224 | + } |
|
| 225 | + } |
|
| 226 | 226 | } |
@@ -47,7 +47,7 @@ |
||
| 47 | 47 | $this->skipLoginCheck = property_exists($this, 'skipLoginCheck') ? $this->skipLoginCheck : []; |
| 48 | 48 | |
| 49 | 49 | $this->relations = array_key_exists($this->model, $this->config['relations']) ? $this->config['relations'][$this->model] : false; |
| 50 | - $route = explode('@',\Route::currentRouteAction())[1]; |
|
| 50 | + $route = explode('@', \Route::currentRouteAction())[1]; |
|
| 51 | 51 | $this->checkPermission(explode('_', snake_case($route))[1]); |
| 52 | 52 | } |
| 53 | 53 | |
@@ -190,8 +190,7 @@ discard block |
||
| 190 | 190 | if ($request->has('id')) |
| 191 | 191 | { |
| 192 | 192 | $rule = str_replace('{id}', $request->get('id'), $rule); |
| 193 | - } |
|
| 194 | - else |
|
| 193 | + } else |
|
| 195 | 194 | { |
| 196 | 195 | $rule = str_replace(',{id}', '', $rule); |
| 197 | 196 | } |
@@ -232,8 +231,7 @@ discard block |
||
| 232 | 231 | { |
| 233 | 232 | $error = $this->errorHandler->notFound('method'); |
| 234 | 233 | abort($error['status'], $error['message']); |
| 235 | - } |
|
| 236 | - else if ( ! in_array($permission, $this->skipLoginCheck)) |
|
| 234 | + } else if ( ! in_array($permission, $this->skipLoginCheck)) |
|
| 237 | 235 | { |
| 238 | 236 | \JWTAuth::parseToken()->authenticate(); |
| 239 | 237 | if ( ! in_array($permission, $this->skipPermissionCheck) && ! \Core::users()->can($permission, $this->model)) |
@@ -46,7 +46,7 @@ |
||
| 46 | 46 | * |
| 47 | 47 | * @param array $conditions array of conditions |
| 48 | 48 | * @param array $relations |
| 49 | - * @param array $colunmns |
|
| 49 | + * @param array $columns |
|
| 50 | 50 | * @return object |
| 51 | 51 | */ |
| 52 | 52 | public function first($conditions, $relations = [], $columns = array('*')) |
@@ -11,59 +11,59 @@ |
||
| 11 | 11 | */ |
| 12 | 12 | protected function getModel() |
| 13 | 13 | { |
| 14 | - $apiVersion = \Request::header('api-version') ?: 1; |
|
| 14 | + $apiVersion = \Request::header('api-version') ?: 1; |
|
| 15 | 15 | return 'App\Modules\V1\Reporting\Report'; |
| 16 | 16 | } |
| 17 | 17 | |
| 18 | 18 | /** |
| 19 | - * Render the given report db view. |
|
| 20 | - * |
|
| 21 | - * @param integer $id |
|
| 22 | - * @param array $relations |
|
| 23 | - * @param array $columns |
|
| 24 | - * @return object |
|
| 25 | - */ |
|
| 26 | - public function find($id, $relations = [], $columns = array('*')) |
|
| 27 | - { |
|
| 19 | + * Render the given report db view. |
|
| 20 | + * |
|
| 21 | + * @param integer $id |
|
| 22 | + * @param array $relations |
|
| 23 | + * @param array $columns |
|
| 24 | + * @return object |
|
| 25 | + */ |
|
| 26 | + public function find($id, $relations = [], $columns = array('*')) |
|
| 27 | + { |
|
| 28 | 28 | $report = call_user_func_array("{$this->getModel()}::with", array($relations))->find($id, $columns); |
| 29 | 29 | |
| 30 | - if ( ! $report) |
|
| 31 | - { |
|
| 32 | - \ErrorHandler::notFound('report'); |
|
| 33 | - } |
|
| 30 | + if ( ! $report) |
|
| 31 | + { |
|
| 32 | + \ErrorHandler::notFound('report'); |
|
| 33 | + } |
|
| 34 | 34 | |
| 35 | - if ( ! \Core::users()->can($report->view_name, 'reports')) |
|
| 36 | - { |
|
| 37 | - \ErrorHandler::noPermissions(); |
|
| 38 | - } |
|
| 35 | + if ( ! \Core::users()->can($report->view_name, 'reports')) |
|
| 36 | + { |
|
| 37 | + \ErrorHandler::noPermissions(); |
|
| 38 | + } |
|
| 39 | 39 | |
| 40 | - return \DB::table($report->view_name)->get(); |
|
| 41 | - } |
|
| 40 | + return \DB::table($report->view_name)->get(); |
|
| 41 | + } |
|
| 42 | 42 | |
| 43 | - /** |
|
| 44 | - * Render the given report db view based on the given |
|
| 45 | - * condition. |
|
| 46 | - * |
|
| 47 | - * @param array $conditions array of conditions |
|
| 48 | - * @param array $relations |
|
| 49 | - * @param array $colunmns |
|
| 50 | - * @return object |
|
| 51 | - */ |
|
| 52 | - public function first($conditions, $relations = [], $columns = array('*')) |
|
| 53 | - { |
|
| 43 | + /** |
|
| 44 | + * Render the given report db view based on the given |
|
| 45 | + * condition. |
|
| 46 | + * |
|
| 47 | + * @param array $conditions array of conditions |
|
| 48 | + * @param array $relations |
|
| 49 | + * @param array $colunmns |
|
| 50 | + * @return object |
|
| 51 | + */ |
|
| 52 | + public function first($conditions, $relations = [], $columns = array('*')) |
|
| 53 | + { |
|
| 54 | 54 | $conditions = $this->constructConditions($conditions); |
| 55 | 55 | $report = call_user_func_array("{$this->getModel()}::with", array($relations))->whereRaw($conditions['conditionString'], $conditions['conditionValues'])->first($columns); |
| 56 | 56 | |
| 57 | - if ( ! $report) |
|
| 58 | - { |
|
| 59 | - \ErrorHandler::notFound('report'); |
|
| 60 | - } |
|
| 57 | + if ( ! $report) |
|
| 58 | + { |
|
| 59 | + \ErrorHandler::notFound('report'); |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | - if ( ! \Core::users()->can($report->view_name, 'reports')) |
|
| 63 | - { |
|
| 64 | - \ErrorHandler::noPermissions(); |
|
| 65 | - } |
|
| 62 | + if ( ! \Core::users()->can($report->view_name, 'reports')) |
|
| 63 | + { |
|
| 64 | + \ErrorHandler::noPermissions(); |
|
| 65 | + } |
|
| 66 | 66 | |
| 67 | - return \DB::table($report->view_name)->get(); |
|
| 68 | - } |
|
| 67 | + return \DB::table($report->view_name)->get(); |
|
| 68 | + } |
|
| 69 | 69 | } |
@@ -2,18 +2,18 @@ |
||
| 2 | 2 | |
| 3 | 3 | class Log |
| 4 | 4 | { |
| 5 | - public function saveLog($action, $item_name, $item_type, $item_id, $model = false) |
|
| 6 | - { |
|
| 7 | - if (\Core::logs() && $item_name !== 'Log') |
|
| 8 | - { |
|
| 9 | - $item_name = $item_name; |
|
| 10 | - \Core::logs()->save([ |
|
| 11 | - 'action' => $action, |
|
| 12 | - 'item_name' => $item_name, |
|
| 13 | - 'item_type' => $item_type, |
|
| 14 | - 'item_id' => $item_id, |
|
| 15 | - 'user_id' => \JWTAuth::parseToken()->authenticate()->id, |
|
| 16 | - ], false, false); |
|
| 17 | - } |
|
| 18 | - } |
|
| 5 | + public function saveLog($action, $item_name, $item_type, $item_id, $model = false) |
|
| 6 | + { |
|
| 7 | + if (\Core::logs() && $item_name !== 'Log') |
|
| 8 | + { |
|
| 9 | + $item_name = $item_name; |
|
| 10 | + \Core::logs()->save([ |
|
| 11 | + 'action' => $action, |
|
| 12 | + 'item_name' => $item_name, |
|
| 13 | + 'item_type' => $item_type, |
|
| 14 | + 'item_id' => $item_id, |
|
| 15 | + 'user_id' => \JWTAuth::parseToken()->authenticate()->id, |
|
| 16 | + ], false, false); |
|
| 17 | + } |
|
| 18 | + } |
|
| 19 | 19 | } |
| 20 | 20 | \ No newline at end of file |
@@ -2,14 +2,14 @@ discard block |
||
| 2 | 2 | |
| 3 | 3 | class CoreConfig |
| 4 | 4 | { |
| 5 | - public function getConfig() |
|
| 6 | - { |
|
| 7 | - $customSettings = []; |
|
| 8 | - Settings::get(['key', 'value'])->each(function ($setting) use (&$customSettings){ |
|
| 9 | - $customSettings[$setting['key']] = $setting['value']; |
|
| 10 | - }); |
|
| 5 | + public function getConfig() |
|
| 6 | + { |
|
| 7 | + $customSettings = []; |
|
| 8 | + Settings::get(['key', 'value'])->each(function ($setting) use (&$customSettings){ |
|
| 9 | + $customSettings[$setting['key']] = $setting['value']; |
|
| 10 | + }); |
|
| 11 | 11 | |
| 12 | - return array_merge($customSettings, [ |
|
| 12 | + return array_merge($customSettings, [ |
|
| 13 | 13 | /** |
| 14 | 14 | * Specify what relations should be used for every model. |
| 15 | 15 | */ |
@@ -56,5 +56,5 @@ discard block |
||
| 56 | 56 | ], |
| 57 | 57 | ] |
| 58 | 58 | ]); |
| 59 | - } |
|
| 59 | + } |
|
| 60 | 60 | } |
| 61 | 61 | \ No newline at end of file |
@@ -5,7 +5,7 @@ |
||
| 5 | 5 | public function getConfig() |
| 6 | 6 | { |
| 7 | 7 | $customSettings = []; |
| 8 | - Settings::get(['key', 'value'])->each(function ($setting) use (&$customSettings){ |
|
| 8 | + Settings::get(['key', 'value'])->each(function($setting) use (&$customSettings){ |
|
| 9 | 9 | $customSettings[$setting['key']] = $setting['value']; |
| 10 | 10 | }); |
| 11 | 11 | |
@@ -5,41 +5,41 @@ |
||
| 5 | 5 | |
| 6 | 6 | class Log extends Model{ |
| 7 | 7 | |
| 8 | - use SoftDeletes; |
|
| 9 | - protected $table = 'logs'; |
|
| 10 | - protected $dates = ['created_at', 'updated_at', 'deleted_at']; |
|
| 11 | - protected $hidden = ['deleted_at', 'item_type']; |
|
| 12 | - protected $guarded = ['id']; |
|
| 13 | - protected $fillable = ['action', 'item_name', 'item_type', 'item_id', 'user_id']; |
|
| 14 | - |
|
| 15 | - public function getCreatedAtAttribute($value) |
|
| 16 | - { |
|
| 17 | - return \Carbon\Carbon::parse($value)->addHours(\Session::get('timeZoneDiff'))->toDateTimeString(); |
|
| 18 | - } |
|
| 19 | - |
|
| 20 | - public function getUpdatedAtAttribute($value) |
|
| 21 | - { |
|
| 22 | - return \Carbon\Carbon::parse($value)->addHours(\Session::get('timeZoneDiff'))->toDateTimeString(); |
|
| 23 | - } |
|
| 24 | - |
|
| 25 | - public function getDeletedAtAttribute($value) |
|
| 26 | - { |
|
| 27 | - return \Carbon\Carbon::parse($value)->addHours(\Session::get('timeZoneDiff'))->toDateTimeString(); |
|
| 28 | - } |
|
| 8 | + use SoftDeletes; |
|
| 9 | + protected $table = 'logs'; |
|
| 10 | + protected $dates = ['created_at', 'updated_at', 'deleted_at']; |
|
| 11 | + protected $hidden = ['deleted_at', 'item_type']; |
|
| 12 | + protected $guarded = ['id']; |
|
| 13 | + protected $fillable = ['action', 'item_name', 'item_type', 'item_id', 'user_id']; |
|
| 14 | + |
|
| 15 | + public function getCreatedAtAttribute($value) |
|
| 16 | + { |
|
| 17 | + return \Carbon\Carbon::parse($value)->addHours(\Session::get('timeZoneDiff'))->toDateTimeString(); |
|
| 18 | + } |
|
| 19 | + |
|
| 20 | + public function getUpdatedAtAttribute($value) |
|
| 21 | + { |
|
| 22 | + return \Carbon\Carbon::parse($value)->addHours(\Session::get('timeZoneDiff'))->toDateTimeString(); |
|
| 23 | + } |
|
| 24 | + |
|
| 25 | + public function getDeletedAtAttribute($value) |
|
| 26 | + { |
|
| 27 | + return \Carbon\Carbon::parse($value)->addHours(\Session::get('timeZoneDiff'))->toDateTimeString(); |
|
| 28 | + } |
|
| 29 | 29 | |
| 30 | - public function user() |
|
| 31 | - { |
|
| 32 | - return $this->belongsTo('App\Modules\V1\Acl\AclUser'); |
|
| 33 | - } |
|
| 34 | - |
|
| 35 | - public function item() |
|
| 36 | - { |
|
| 37 | - return $this->morphTo(); |
|
| 38 | - } |
|
| 39 | - |
|
| 40 | - public static function boot() |
|
| 41 | - { |
|
| 42 | - parent::boot(); |
|
| 43 | - parent::observe(\App::make('App\Modules\V1\Core\ModelObservers\LogObserver')); |
|
| 44 | - } |
|
| 30 | + public function user() |
|
| 31 | + { |
|
| 32 | + return $this->belongsTo('App\Modules\V1\Acl\AclUser'); |
|
| 33 | + } |
|
| 34 | + |
|
| 35 | + public function item() |
|
| 36 | + { |
|
| 37 | + return $this->morphTo(); |
|
| 38 | + } |
|
| 39 | + |
|
| 40 | + public static function boot() |
|
| 41 | + { |
|
| 42 | + parent::boot(); |
|
| 43 | + parent::observe(\App::make('App\Modules\V1\Core\ModelObservers\LogObserver')); |
|
| 44 | + } |
|
| 45 | 45 | } |
@@ -3,7 +3,7 @@ |
||
| 3 | 3 | use Illuminate\Database\Eloquent\Model; |
| 4 | 4 | use Illuminate\Database\Eloquent\SoftDeletes; |
| 5 | 5 | |
| 6 | -class Log extends Model{ |
|
| 6 | +class Log extends Model { |
|
| 7 | 7 | |
| 8 | 8 | use SoftDeletes; |
| 9 | 9 | protected $table = 'logs'; |
@@ -13,13 +13,13 @@ |
||
| 13 | 13 | public function up() |
| 14 | 14 | { |
| 15 | 15 | Schema::create('settings', function (Blueprint $table) { |
| 16 | - $table->increments('id'); |
|
| 17 | - $table->string('name',100); |
|
| 18 | - $table->string('key',100)->unique(); |
|
| 19 | - $table->string('value',100); |
|
| 20 | - $table->softDeletes(); |
|
| 21 | - $table->timestamps(); |
|
| 22 | - }); |
|
| 16 | + $table->increments('id'); |
|
| 17 | + $table->string('name',100); |
|
| 18 | + $table->string('key',100)->unique(); |
|
| 19 | + $table->string('value',100); |
|
| 20 | + $table->softDeletes(); |
|
| 21 | + $table->timestamps(); |
|
| 22 | + }); |
|
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | /** |
@@ -12,11 +12,11 @@ |
||
| 12 | 12 | */ |
| 13 | 13 | public function up() |
| 14 | 14 | { |
| 15 | - Schema::create('settings', function (Blueprint $table) { |
|
| 15 | + Schema::create('settings', function(Blueprint $table) { |
|
| 16 | 16 | $table->increments('id'); |
| 17 | - $table->string('name',100); |
|
| 18 | - $table->string('key',100)->unique(); |
|
| 19 | - $table->string('value',100); |
|
| 17 | + $table->string('name', 100); |
|
| 18 | + $table->string('key', 100)->unique(); |
|
| 19 | + $table->string('value', 100); |
|
| 20 | 20 | $table->softDeletes(); |
| 21 | 21 | $table->timestamps(); |
| 22 | 22 | }); |
@@ -18,7 +18,7 @@ |
||
| 18 | 18 | $table->string('view_name',100); |
| 19 | 19 | $table->softDeletes(); |
| 20 | 20 | $table->timestamps(); |
| 21 | - }); |
|
| 21 | + }); |
|
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | /** |
@@ -12,11 +12,11 @@ |
||
| 12 | 12 | */ |
| 13 | 13 | public function up() |
| 14 | 14 | { |
| 15 | - Schema::create('logs', function (Blueprint $table) { |
|
| 15 | + Schema::create('logs', function(Blueprint $table) { |
|
| 16 | 16 | $table->increments('id'); |
| 17 | - $table->string('action',100); |
|
| 18 | - $table->string('item_name',100); |
|
| 19 | - $table->string('item_type',100); |
|
| 17 | + $table->string('action', 100); |
|
| 18 | + $table->string('item_name', 100); |
|
| 19 | + $table->string('item_type', 100); |
|
| 20 | 20 | $table->integer('item_id'); |
| 21 | 21 | $table->integer('user_id'); |
| 22 | 22 | $table->softDeletes(); |
@@ -12,129 +12,129 @@ |
||
| 12 | 12 | */ |
| 13 | 13 | public function up() |
| 14 | 14 | { |
| 15 | - /** |
|
| 16 | - * Delete previous permissions. |
|
| 17 | - */ |
|
| 15 | + /** |
|
| 16 | + * Delete previous permissions. |
|
| 17 | + */ |
|
| 18 | 18 | DB::table('permissions')->whereIn('model', ['settings'])->delete(); |
| 19 | 19 | |
| 20 | 20 | /** |
| 21 | - * Insert the permissions related to this module. |
|
| 22 | - */ |
|
| 23 | - DB::table('permissions')->insert( |
|
| 24 | - [ |
|
| 25 | - /** |
|
| 26 | - * Users model permissions. |
|
| 27 | - */ |
|
| 28 | - [ |
|
| 29 | - 'name' => 'save', |
|
| 30 | - 'model' => 'settings', |
|
| 31 | - 'created_at' => \DB::raw('NOW()'), |
|
| 32 | - 'updated_at' => \DB::raw('NOW()') |
|
| 33 | - ], |
|
| 34 | - [ |
|
| 35 | - 'name' => 'find', |
|
| 36 | - 'model' => 'settings', |
|
| 37 | - 'created_at' => \DB::raw('NOW()'), |
|
| 38 | - 'updated_at' => \DB::raw('NOW()') |
|
| 39 | - ], |
|
| 40 | - [ |
|
| 41 | - 'name' => 'search', |
|
| 42 | - 'model' => 'settings', |
|
| 43 | - 'created_at' => \DB::raw('NOW()'), |
|
| 44 | - 'updated_at' => \DB::raw('NOW()') |
|
| 45 | - ], |
|
| 46 | - [ |
|
| 47 | - 'name' => 'list', |
|
| 48 | - 'model' => 'settings', |
|
| 49 | - 'created_at' => \DB::raw('NOW()'), |
|
| 50 | - 'updated_at' => \DB::raw('NOW()') |
|
| 51 | - ], |
|
| 52 | - [ |
|
| 53 | - 'name' => 'findby', |
|
| 54 | - 'model' => 'settings', |
|
| 55 | - 'created_at' => \DB::raw('NOW()'), |
|
| 56 | - 'updated_at' => \DB::raw('NOW()') |
|
| 57 | - ], |
|
| 58 | - [ |
|
| 59 | - 'name' => 'first', |
|
| 60 | - 'model' => 'settings', |
|
| 61 | - 'created_at' => \DB::raw('NOW()'), |
|
| 62 | - 'updated_at' => \DB::raw('NOW()') |
|
| 63 | - ], |
|
| 64 | - [ |
|
| 65 | - 'name' => 'paginate', |
|
| 66 | - 'model' => 'settings', |
|
| 67 | - 'created_at' => \DB::raw('NOW()'), |
|
| 68 | - 'updated_at' => \DB::raw('NOW()') |
|
| 69 | - ], |
|
| 70 | - [ |
|
| 71 | - 'name' => 'paginateby', |
|
| 72 | - 'model' => 'settings', |
|
| 73 | - 'created_at' => \DB::raw('NOW()'), |
|
| 74 | - 'updated_at' => \DB::raw('NOW()') |
|
| 75 | - ] |
|
| 76 | - ] |
|
| 77 | - ); |
|
| 21 | + * Insert the permissions related to this module. |
|
| 22 | + */ |
|
| 23 | + DB::table('permissions')->insert( |
|
| 24 | + [ |
|
| 25 | + /** |
|
| 26 | + * Users model permissions. |
|
| 27 | + */ |
|
| 28 | + [ |
|
| 29 | + 'name' => 'save', |
|
| 30 | + 'model' => 'settings', |
|
| 31 | + 'created_at' => \DB::raw('NOW()'), |
|
| 32 | + 'updated_at' => \DB::raw('NOW()') |
|
| 33 | + ], |
|
| 34 | + [ |
|
| 35 | + 'name' => 'find', |
|
| 36 | + 'model' => 'settings', |
|
| 37 | + 'created_at' => \DB::raw('NOW()'), |
|
| 38 | + 'updated_at' => \DB::raw('NOW()') |
|
| 39 | + ], |
|
| 40 | + [ |
|
| 41 | + 'name' => 'search', |
|
| 42 | + 'model' => 'settings', |
|
| 43 | + 'created_at' => \DB::raw('NOW()'), |
|
| 44 | + 'updated_at' => \DB::raw('NOW()') |
|
| 45 | + ], |
|
| 46 | + [ |
|
| 47 | + 'name' => 'list', |
|
| 48 | + 'model' => 'settings', |
|
| 49 | + 'created_at' => \DB::raw('NOW()'), |
|
| 50 | + 'updated_at' => \DB::raw('NOW()') |
|
| 51 | + ], |
|
| 52 | + [ |
|
| 53 | + 'name' => 'findby', |
|
| 54 | + 'model' => 'settings', |
|
| 55 | + 'created_at' => \DB::raw('NOW()'), |
|
| 56 | + 'updated_at' => \DB::raw('NOW()') |
|
| 57 | + ], |
|
| 58 | + [ |
|
| 59 | + 'name' => 'first', |
|
| 60 | + 'model' => 'settings', |
|
| 61 | + 'created_at' => \DB::raw('NOW()'), |
|
| 62 | + 'updated_at' => \DB::raw('NOW()') |
|
| 63 | + ], |
|
| 64 | + [ |
|
| 65 | + 'name' => 'paginate', |
|
| 66 | + 'model' => 'settings', |
|
| 67 | + 'created_at' => \DB::raw('NOW()'), |
|
| 68 | + 'updated_at' => \DB::raw('NOW()') |
|
| 69 | + ], |
|
| 70 | + [ |
|
| 71 | + 'name' => 'paginateby', |
|
| 72 | + 'model' => 'settings', |
|
| 73 | + 'created_at' => \DB::raw('NOW()'), |
|
| 74 | + 'updated_at' => \DB::raw('NOW()') |
|
| 75 | + ] |
|
| 76 | + ] |
|
| 77 | + ); |
|
| 78 | 78 | |
| 79 | - /** |
|
| 80 | - * Delete previous permissions. |
|
| 81 | - */ |
|
| 79 | + /** |
|
| 80 | + * Delete previous permissions. |
|
| 81 | + */ |
|
| 82 | 82 | DB::table('permissions')->whereIn('model', ['logs'])->delete(); |
| 83 | 83 | |
| 84 | 84 | /** |
| 85 | - * Insert the permissions related to this module. |
|
| 86 | - */ |
|
| 87 | - DB::table('permissions')->insert( |
|
| 88 | - [ |
|
| 89 | - /** |
|
| 90 | - * Logs model permissions. |
|
| 91 | - */ |
|
| 92 | - [ |
|
| 93 | - 'name' => 'find', |
|
| 94 | - 'model' => 'logs', |
|
| 95 | - 'created_at' => \DB::raw('NOW()'), |
|
| 96 | - 'updated_at' => \DB::raw('NOW()') |
|
| 97 | - ], |
|
| 98 | - [ |
|
| 99 | - 'name' => 'search', |
|
| 100 | - 'model' => 'logs', |
|
| 101 | - 'created_at' => \DB::raw('NOW()'), |
|
| 102 | - 'updated_at' => \DB::raw('NOW()') |
|
| 103 | - ], |
|
| 104 | - [ |
|
| 105 | - 'name' => 'list', |
|
| 106 | - 'model' => 'logs', |
|
| 107 | - 'created_at' => \DB::raw('NOW()'), |
|
| 108 | - 'updated_at' => \DB::raw('NOW()') |
|
| 109 | - ], |
|
| 110 | - [ |
|
| 111 | - 'name' => 'findby', |
|
| 112 | - 'model' => 'logs', |
|
| 113 | - 'created_at' => \DB::raw('NOW()'), |
|
| 114 | - 'updated_at' => \DB::raw('NOW()') |
|
| 115 | - ], |
|
| 116 | - [ |
|
| 117 | - 'name' => 'first', |
|
| 118 | - 'model' => 'logs', |
|
| 119 | - 'created_at' => \DB::raw('NOW()'), |
|
| 120 | - 'updated_at' => \DB::raw('NOW()') |
|
| 121 | - ], |
|
| 122 | - [ |
|
| 123 | - 'name' => 'paginate', |
|
| 124 | - 'model' => 'logs', |
|
| 125 | - 'created_at' => \DB::raw('NOW()'), |
|
| 126 | - 'updated_at' => \DB::raw('NOW()') |
|
| 127 | - ], |
|
| 128 | - [ |
|
| 129 | - 'name' => 'paginateby', |
|
| 130 | - 'model' => 'logs', |
|
| 131 | - 'created_at' => \DB::raw('NOW()'), |
|
| 132 | - 'updated_at' => \DB::raw('NOW()') |
|
| 133 | - ], |
|
| 134 | - ] |
|
| 135 | - ); |
|
| 85 | + * Insert the permissions related to this module. |
|
| 86 | + */ |
|
| 87 | + DB::table('permissions')->insert( |
|
| 88 | + [ |
|
| 89 | + /** |
|
| 90 | + * Logs model permissions. |
|
| 91 | + */ |
|
| 92 | + [ |
|
| 93 | + 'name' => 'find', |
|
| 94 | + 'model' => 'logs', |
|
| 95 | + 'created_at' => \DB::raw('NOW()'), |
|
| 96 | + 'updated_at' => \DB::raw('NOW()') |
|
| 97 | + ], |
|
| 98 | + [ |
|
| 99 | + 'name' => 'search', |
|
| 100 | + 'model' => 'logs', |
|
| 101 | + 'created_at' => \DB::raw('NOW()'), |
|
| 102 | + 'updated_at' => \DB::raw('NOW()') |
|
| 103 | + ], |
|
| 104 | + [ |
|
| 105 | + 'name' => 'list', |
|
| 106 | + 'model' => 'logs', |
|
| 107 | + 'created_at' => \DB::raw('NOW()'), |
|
| 108 | + 'updated_at' => \DB::raw('NOW()') |
|
| 109 | + ], |
|
| 110 | + [ |
|
| 111 | + 'name' => 'findby', |
|
| 112 | + 'model' => 'logs', |
|
| 113 | + 'created_at' => \DB::raw('NOW()'), |
|
| 114 | + 'updated_at' => \DB::raw('NOW()') |
|
| 115 | + ], |
|
| 116 | + [ |
|
| 117 | + 'name' => 'first', |
|
| 118 | + 'model' => 'logs', |
|
| 119 | + 'created_at' => \DB::raw('NOW()'), |
|
| 120 | + 'updated_at' => \DB::raw('NOW()') |
|
| 121 | + ], |
|
| 122 | + [ |
|
| 123 | + 'name' => 'paginate', |
|
| 124 | + 'model' => 'logs', |
|
| 125 | + 'created_at' => \DB::raw('NOW()'), |
|
| 126 | + 'updated_at' => \DB::raw('NOW()') |
|
| 127 | + ], |
|
| 128 | + [ |
|
| 129 | + 'name' => 'paginateby', |
|
| 130 | + 'model' => 'logs', |
|
| 131 | + 'created_at' => \DB::raw('NOW()'), |
|
| 132 | + 'updated_at' => \DB::raw('NOW()') |
|
| 133 | + ], |
|
| 134 | + ] |
|
| 135 | + ); |
|
| 136 | 136 | |
| 137 | - /** |
|
| 137 | + /** |
|
| 138 | 138 | * Assign the permissions to the admin group. |
| 139 | 139 | */ |
| 140 | 140 | $permissionIds = DB::table('permissions')->whereIn('model', ['settings', 'logs'])->select('id')->lists('id'); |