@@ -5,47 +5,47 @@ |
||
5 | 5 | |
6 | 6 | class AclGroup extends Model{ |
7 | 7 | |
8 | - use SoftDeletes; |
|
9 | - protected $table = 'groups'; |
|
10 | - protected $dates = ['created_at', 'updated_at', 'deleted_at']; |
|
11 | - protected $hidden = ['deleted_at']; |
|
12 | - protected $guarded = ['id']; |
|
13 | - protected $fillable = ['name']; |
|
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 | - |
|
30 | - public function users() |
|
31 | - { |
|
32 | - return $this->belongsToMany('\App\Modules\Acl\AclUser','users_groups','group_id','user_id')->whereNull('users_groups.deleted_at')->withTimestamps(); |
|
33 | - } |
|
34 | - |
|
35 | - public function permissions() |
|
36 | - { |
|
37 | - return $this->belongsToMany('\App\Modules\Acl\AclPermission','groups_permissions','group_id','permission_id')->whereNull('groups_permissions.deleted_at')->withTimestamps(); |
|
38 | - } |
|
39 | - |
|
40 | - public static function boot() |
|
41 | - { |
|
42 | - parent::boot(); |
|
43 | - |
|
44 | - AclGroup::deleting(function($group) |
|
45 | - { |
|
46 | - \DB::table('groups_permissions') |
|
47 | - ->where('group_id', $group->id) |
|
48 | - ->update(array('deleted_at' => \DB::raw('NOW()'))); |
|
49 | - }); |
|
50 | - } |
|
8 | + use SoftDeletes; |
|
9 | + protected $table = 'groups'; |
|
10 | + protected $dates = ['created_at', 'updated_at', 'deleted_at']; |
|
11 | + protected $hidden = ['deleted_at']; |
|
12 | + protected $guarded = ['id']; |
|
13 | + protected $fillable = ['name']; |
|
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 | + |
|
30 | + public function users() |
|
31 | + { |
|
32 | + return $this->belongsToMany('\App\Modules\Acl\AclUser','users_groups','group_id','user_id')->whereNull('users_groups.deleted_at')->withTimestamps(); |
|
33 | + } |
|
34 | + |
|
35 | + public function permissions() |
|
36 | + { |
|
37 | + return $this->belongsToMany('\App\Modules\Acl\AclPermission','groups_permissions','group_id','permission_id')->whereNull('groups_permissions.deleted_at')->withTimestamps(); |
|
38 | + } |
|
39 | + |
|
40 | + public static function boot() |
|
41 | + { |
|
42 | + parent::boot(); |
|
43 | + |
|
44 | + AclGroup::deleting(function($group) |
|
45 | + { |
|
46 | + \DB::table('groups_permissions') |
|
47 | + ->where('group_id', $group->id) |
|
48 | + ->update(array('deleted_at' => \DB::raw('NOW()'))); |
|
49 | + }); |
|
50 | + } |
|
51 | 51 | } |
@@ -61,6 +61,6 @@ |
||
61 | 61 | $user->groups()->attach($group_ids); |
62 | 62 | }); |
63 | 63 | |
64 | - return \Core::users()->find($user_id); |
|
64 | + return \Core::users()->find($user_id); |
|
65 | 65 | } |
66 | 66 | } |
@@ -29,6 +29,6 @@ |
||
29 | 29 | $group->permissions()->attach($permission_ids); |
30 | 30 | }); |
31 | 31 | |
32 | - return \Core::groups()->find($group_id); |
|
32 | + return \Core::groups()->find($group_id); |
|
33 | 33 | } |
34 | 34 | } |
@@ -8,35 +8,35 @@ |
||
8 | 8 | |
9 | 9 | class GroupsController extends BaseApiController |
10 | 10 | { |
11 | - /** |
|
12 | - * The name of the model that is used by the base api controller |
|
13 | - * to preform actions like (add, edit ... etc). |
|
14 | - * @var string |
|
15 | - */ |
|
16 | - protected $model = 'groups'; |
|
11 | + /** |
|
12 | + * The name of the model that is used by the base api controller |
|
13 | + * to preform actions like (add, edit ... etc). |
|
14 | + * @var string |
|
15 | + */ |
|
16 | + protected $model = 'groups'; |
|
17 | 17 | |
18 | - /** |
|
19 | - * The validations rules used by the base api controller |
|
20 | - * to check before add. |
|
21 | - * @var array |
|
22 | - */ |
|
23 | - protected $validationRules = [ |
|
24 | - 'name' => 'required|string|max:100|unique:groups,name,{id}' |
|
25 | - ]; |
|
18 | + /** |
|
19 | + * The validations rules used by the base api controller |
|
20 | + * to check before add. |
|
21 | + * @var array |
|
22 | + */ |
|
23 | + protected $validationRules = [ |
|
24 | + 'name' => 'required|string|max:100|unique:groups,name,{id}' |
|
25 | + ]; |
|
26 | 26 | |
27 | - /** |
|
28 | - * Handle an assign permissions to group request. |
|
29 | - * |
|
30 | - * @param \Illuminate\Http\Request $request |
|
31 | - * @return \Illuminate\Http\Response |
|
32 | - */ |
|
33 | - public function postAssignpermissions(Request $request) |
|
34 | - { |
|
35 | - $this->validate($request, [ |
|
36 | - 'permission_ids' => 'required|exists:permissions,id', |
|
37 | - 'group_id' => 'required|exists:groups,id' |
|
38 | - ]); |
|
27 | + /** |
|
28 | + * Handle an assign permissions to group request. |
|
29 | + * |
|
30 | + * @param \Illuminate\Http\Request $request |
|
31 | + * @return \Illuminate\Http\Response |
|
32 | + */ |
|
33 | + public function postAssignpermissions(Request $request) |
|
34 | + { |
|
35 | + $this->validate($request, [ |
|
36 | + 'permission_ids' => 'required|exists:permissions,id', |
|
37 | + 'group_id' => 'required|exists:groups,id' |
|
38 | + ]); |
|
39 | 39 | |
40 | - return \Response::json(\Core::groups()->assignPermissions($request->get('group_id'), $request->get('permission_ids')), 200); |
|
41 | - } |
|
40 | + return \Response::json(\Core::groups()->assignPermissions($request->get('group_id'), $request->get('permission_ids')), 200); |
|
41 | + } |
|
42 | 42 | } |
@@ -7,10 +7,10 @@ |
||
7 | 7 | |
8 | 8 | class PermissionsController extends BaseApiController |
9 | 9 | { |
10 | - /** |
|
11 | - * The name of the model that is used by the base api controller |
|
12 | - * to preform actions like (add, edit ... etc). |
|
13 | - * @var string |
|
14 | - */ |
|
15 | - protected $model = 'permissions'; |
|
10 | + /** |
|
11 | + * The name of the model that is used by the base api controller |
|
12 | + * to preform actions like (add, edit ... etc). |
|
13 | + * @var string |
|
14 | + */ |
|
15 | + protected $model = 'permissions'; |
|
16 | 16 | } |
@@ -13,17 +13,17 @@ |
||
13 | 13 | public function up() |
14 | 14 | { |
15 | 15 | Schema::create('users', function (Blueprint $table) { |
16 | - $table->increments('id'); |
|
17 | - $table->string('first_name',100)->nullable(); |
|
18 | - $table->string('last_name',100)->nullable(); |
|
19 | - $table->string('user_name',100)->nullable(); |
|
20 | - $table->text('address')->nullable(); |
|
21 | - $table->string('email')->unique(); |
|
22 | - $table->string('password', 60); |
|
23 | - $table->softDeletes(); |
|
24 | - $table->rememberToken(); |
|
25 | - $table->timestamps(); |
|
26 | - }); |
|
16 | + $table->increments('id'); |
|
17 | + $table->string('first_name',100)->nullable(); |
|
18 | + $table->string('last_name',100)->nullable(); |
|
19 | + $table->string('user_name',100)->nullable(); |
|
20 | + $table->text('address')->nullable(); |
|
21 | + $table->string('email')->unique(); |
|
22 | + $table->string('password', 60); |
|
23 | + $table->softDeletes(); |
|
24 | + $table->rememberToken(); |
|
25 | + $table->timestamps(); |
|
26 | + }); |
|
27 | 27 | } |
28 | 28 | |
29 | 29 | /** |
@@ -12,21 +12,21 @@ |
||
12 | 12 | */ |
13 | 13 | public function up() |
14 | 14 | { |
15 | - Schema::create('permissions', function (Blueprint $table) { |
|
16 | - $table->increments('id'); |
|
17 | - $table->string('name',100); |
|
18 | - $table->string('model',100); |
|
19 | - $table->softDeletes(); |
|
20 | - $table->timestamps(); |
|
21 | - $table->unique(array('name', 'model')); |
|
22 | - }); |
|
23 | - Schema::create('groups_permissions', function (Blueprint $table) { |
|
24 | - $table->increments('id'); |
|
25 | - $table->integer('group_id'); |
|
26 | - $table->integer('permission_id'); |
|
27 | - $table->softDeletes(); |
|
28 | - $table->timestamps(); |
|
29 | - }); |
|
15 | + Schema::create('permissions', function (Blueprint $table) { |
|
16 | + $table->increments('id'); |
|
17 | + $table->string('name',100); |
|
18 | + $table->string('model',100); |
|
19 | + $table->softDeletes(); |
|
20 | + $table->timestamps(); |
|
21 | + $table->unique(array('name', 'model')); |
|
22 | + }); |
|
23 | + Schema::create('groups_permissions', function (Blueprint $table) { |
|
24 | + $table->increments('id'); |
|
25 | + $table->integer('group_id'); |
|
26 | + $table->integer('permission_id'); |
|
27 | + $table->softDeletes(); |
|
28 | + $table->timestamps(); |
|
29 | + }); |
|
30 | 30 | } |
31 | 31 | |
32 | 32 | /** |
@@ -13,19 +13,19 @@ |
||
13 | 13 | public function up() |
14 | 14 | { |
15 | 15 | Schema::create('groups', function (Blueprint $table) { |
16 | - $table->increments('id'); |
|
17 | - $table->string('name',100)->unique(); |
|
18 | - $table->softDeletes(); |
|
19 | - $table->timestamps(); |
|
20 | - }); |
|
16 | + $table->increments('id'); |
|
17 | + $table->string('name',100)->unique(); |
|
18 | + $table->softDeletes(); |
|
19 | + $table->timestamps(); |
|
20 | + }); |
|
21 | 21 | |
22 | - Schema::create('users_groups', function (Blueprint $table) { |
|
23 | - $table->increments('id'); |
|
24 | - $table->integer('user_id'); |
|
25 | - $table->integer('group_id'); |
|
26 | - $table->softDeletes(); |
|
27 | - $table->timestamps(); |
|
28 | - }); |
|
22 | + Schema::create('users_groups', function (Blueprint $table) { |
|
23 | + $table->increments('id'); |
|
24 | + $table->integer('user_id'); |
|
25 | + $table->integer('group_id'); |
|
26 | + $table->softDeletes(); |
|
27 | + $table->timestamps(); |
|
28 | + }); |
|
29 | 29 | } |
30 | 30 | |
31 | 31 | /** |
@@ -5,42 +5,42 @@ |
||
5 | 5 | |
6 | 6 | class AclPermission extends Model { |
7 | 7 | |
8 | - use SoftDeletes; |
|
9 | - protected $table = 'permissions'; |
|
10 | - protected $dates = ['created_at', 'updated_at', 'deleted_at']; |
|
11 | - protected $hidden = ['deleted_at']; |
|
12 | - protected $guarded = ['id']; |
|
13 | - protected $fillable = ['name', 'model']; |
|
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 = 'permissions'; |
|
10 | + protected $dates = ['created_at', 'updated_at', 'deleted_at']; |
|
11 | + protected $hidden = ['deleted_at']; |
|
12 | + protected $guarded = ['id']; |
|
13 | + protected $fillable = ['name', 'model']; |
|
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 groups() |
|
31 | - { |
|
32 | - return $this->belongsToMany('\App\Modules\Acl\AclGroup','groups_permissions','permission_id','group_id')->whereNull('groups_permissions.deleted_at')->withTimestamps(); |
|
33 | - } |
|
34 | - |
|
35 | - public static function boot() |
|
36 | - { |
|
37 | - parent::boot(); |
|
38 | - |
|
39 | - AclPermission::deleting(function($permission) |
|
40 | - { |
|
41 | - \DB::table('groups_permissions') |
|
42 | - ->where('permission_id', $permission->id) |
|
43 | - ->update(array('deleted_at' => \DB::raw('NOW()'))); |
|
44 | - }); |
|
45 | - } |
|
30 | + public function groups() |
|
31 | + { |
|
32 | + return $this->belongsToMany('\App\Modules\Acl\AclGroup','groups_permissions','permission_id','group_id')->whereNull('groups_permissions.deleted_at')->withTimestamps(); |
|
33 | + } |
|
34 | + |
|
35 | + public static function boot() |
|
36 | + { |
|
37 | + parent::boot(); |
|
38 | + |
|
39 | + AclPermission::deleting(function($permission) |
|
40 | + { |
|
41 | + \DB::table('groups_permissions') |
|
42 | + ->where('permission_id', $permission->id) |
|
43 | + ->update(array('deleted_at' => \DB::raw('NOW()'))); |
|
44 | + }); |
|
45 | + } |
|
46 | 46 | } |