@@ -5,63 +5,63 @@ |
||
| 5 | 5 | |
| 6 | 6 | class OauthClientService extends BaseService |
| 7 | 7 | { |
| 8 | - /** |
|
| 9 | - * Init new object. |
|
| 10 | - * |
|
| 11 | - * @param OauthClientRepository $repo |
|
| 12 | - * @return void |
|
| 13 | - */ |
|
| 14 | - public function __construct(OauthClientRepository $repo) |
|
| 15 | - { |
|
| 16 | - parent::__construct($repo); |
|
| 17 | - } |
|
| 8 | + /** |
|
| 9 | + * Init new object. |
|
| 10 | + * |
|
| 11 | + * @param OauthClientRepository $repo |
|
| 12 | + * @return void |
|
| 13 | + */ |
|
| 14 | + public function __construct(OauthClientRepository $repo) |
|
| 15 | + { |
|
| 16 | + parent::__construct($repo); |
|
| 17 | + } |
|
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * Revoke the given client. |
|
| 21 | - * |
|
| 22 | - * @param integer $clientId |
|
| 23 | - * @return void |
|
| 24 | - */ |
|
| 25 | - public function revoke($clientId) |
|
| 26 | - { |
|
| 27 | - \DB::transaction(function () use ($data) { |
|
| 28 | - $client = $this->repo->find($clientId); |
|
| 29 | - $this->repo->revokeClientTokens($client); |
|
| 30 | - $this->repo->save(['id'=> $clientId, 'revoked' => true]); |
|
| 31 | - }); |
|
| 32 | - } |
|
| 19 | + /** |
|
| 20 | + * Revoke the given client. |
|
| 21 | + * |
|
| 22 | + * @param integer $clientId |
|
| 23 | + * @return void |
|
| 24 | + */ |
|
| 25 | + public function revoke($clientId) |
|
| 26 | + { |
|
| 27 | + \DB::transaction(function () use ($data) { |
|
| 28 | + $client = $this->repo->find($clientId); |
|
| 29 | + $this->repo->revokeClientTokens($client); |
|
| 30 | + $this->repo->save(['id'=> $clientId, 'revoked' => true]); |
|
| 31 | + }); |
|
| 32 | + } |
|
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * UnRevoke the given client. |
|
| 36 | - * |
|
| 37 | - * @param integer $clientId |
|
| 38 | - * @return void |
|
| 39 | - */ |
|
| 40 | - public function unRevoke($clientId) |
|
| 41 | - { |
|
| 42 | - $this->repo->save(['id'=> $clientId, 'revoked' => false]); |
|
| 43 | - } |
|
| 34 | + /** |
|
| 35 | + * UnRevoke the given client. |
|
| 36 | + * |
|
| 37 | + * @param integer $clientId |
|
| 38 | + * @return void |
|
| 39 | + */ |
|
| 40 | + public function unRevoke($clientId) |
|
| 41 | + { |
|
| 42 | + $this->repo->save(['id'=> $clientId, 'revoked' => false]); |
|
| 43 | + } |
|
| 44 | 44 | |
| 45 | - /** |
|
| 46 | - * Ensure access token hasn't expired or revoked. |
|
| 47 | - * |
|
| 48 | - * @param string $accessToken |
|
| 49 | - * @return boolean |
|
| 50 | - */ |
|
| 51 | - public function accessTokenExpiredOrRevoked($accessToken) |
|
| 52 | - { |
|
| 53 | - return $this->oauthClientRepository->accessTokenExpiredOrRevoked($accessToken); |
|
| 54 | - } |
|
| 45 | + /** |
|
| 46 | + * Ensure access token hasn't expired or revoked. |
|
| 47 | + * |
|
| 48 | + * @param string $accessToken |
|
| 49 | + * @return boolean |
|
| 50 | + */ |
|
| 51 | + public function accessTokenExpiredOrRevoked($accessToken) |
|
| 52 | + { |
|
| 53 | + return $this->oauthClientRepository->accessTokenExpiredOrRevoked($accessToken); |
|
| 54 | + } |
|
| 55 | 55 | |
| 56 | - /** |
|
| 57 | - * Revoke the given access token and all |
|
| 58 | - * associated refresh tokens. |
|
| 59 | - * |
|
| 60 | - * @param oject $accessToken |
|
| 61 | - * @return void |
|
| 62 | - */ |
|
| 63 | - public function revokeAccessToken($accessToken) |
|
| 64 | - { |
|
| 65 | - return $this->oauthClientRepository->revokeAccessToken($accessToken); |
|
| 66 | - } |
|
| 56 | + /** |
|
| 57 | + * Revoke the given access token and all |
|
| 58 | + * associated refresh tokens. |
|
| 59 | + * |
|
| 60 | + * @param oject $accessToken |
|
| 61 | + * @return void |
|
| 62 | + */ |
|
| 63 | + public function revokeAccessToken($accessToken) |
|
| 64 | + { |
|
| 65 | + return $this->oauthClientRepository->revokeAccessToken($accessToken); |
|
| 66 | + } |
|
| 67 | 67 | } |
@@ -24,7 +24,7 @@ |
||
| 24 | 24 | */ |
| 25 | 25 | public function revoke($clientId) |
| 26 | 26 | { |
| 27 | - \DB::transaction(function () use ($data) { |
|
| 27 | + \DB::transaction(function() use ($data) { |
|
| 28 | 28 | $client = $this->repo->find($clientId); |
| 29 | 29 | $this->repo->revokeClientTokens($client); |
| 30 | 30 | $this->repo->save(['id'=> $clientId, 'revoked' => true]); |
@@ -5,59 +5,59 @@ |
||
| 5 | 5 | |
| 6 | 6 | class NotificationRepository extends BaseRepository |
| 7 | 7 | { |
| 8 | - /** |
|
| 9 | - * Init new object. |
|
| 10 | - * |
|
| 11 | - * @param Notification $model |
|
| 12 | - * @return void |
|
| 13 | - */ |
|
| 14 | - public function __construct(Notification $model) |
|
| 15 | - { |
|
| 16 | - parent::__construct($model); |
|
| 17 | - } |
|
| 8 | + /** |
|
| 9 | + * Init new object. |
|
| 10 | + * |
|
| 11 | + * @param Notification $model |
|
| 12 | + * @return void |
|
| 13 | + */ |
|
| 14 | + public function __construct(Notification $model) |
|
| 15 | + { |
|
| 16 | + parent::__construct($model); |
|
| 17 | + } |
|
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * Retrieve all notifications of the logged in user. |
|
| 21 | - * |
|
| 22 | - * @param integer $perPage |
|
| 23 | - * @return Collection |
|
| 24 | - */ |
|
| 25 | - public function my($perPage) |
|
| 26 | - { |
|
| 27 | - return \Auth::user()->notifications()->paginate($perPage); |
|
| 28 | - } |
|
| 19 | + /** |
|
| 20 | + * Retrieve all notifications of the logged in user. |
|
| 21 | + * |
|
| 22 | + * @param integer $perPage |
|
| 23 | + * @return Collection |
|
| 24 | + */ |
|
| 25 | + public function my($perPage) |
|
| 26 | + { |
|
| 27 | + return \Auth::user()->notifications()->paginate($perPage); |
|
| 28 | + } |
|
| 29 | 29 | |
| 30 | - /** |
|
| 31 | - * Retrieve unread notifications of the logged in user. |
|
| 32 | - * |
|
| 33 | - * @param integer $perPage |
|
| 34 | - * @return Collection |
|
| 35 | - */ |
|
| 36 | - public function unread($perPage) |
|
| 37 | - { |
|
| 38 | - return \Auth::user()->unreadNotifications()->paginate($perPage); |
|
| 39 | - } |
|
| 30 | + /** |
|
| 31 | + * Retrieve unread notifications of the logged in user. |
|
| 32 | + * |
|
| 33 | + * @param integer $perPage |
|
| 34 | + * @return Collection |
|
| 35 | + */ |
|
| 36 | + public function unread($perPage) |
|
| 37 | + { |
|
| 38 | + return \Auth::user()->unreadNotifications()->paginate($perPage); |
|
| 39 | + } |
|
| 40 | 40 | |
| 41 | - /** |
|
| 42 | - * Mark the notification as read. |
|
| 43 | - * |
|
| 44 | - * @param integer $id |
|
| 45 | - * @return object |
|
| 46 | - */ |
|
| 47 | - public function markAsRead($id) |
|
| 48 | - { |
|
| 49 | - if ($notification = \Auth::user()->unreadNotifications()->where('id', $id)->first()) { |
|
| 50 | - $notification->markAsRead(); |
|
| 51 | - } |
|
| 52 | - } |
|
| 41 | + /** |
|
| 42 | + * Mark the notification as read. |
|
| 43 | + * |
|
| 44 | + * @param integer $id |
|
| 45 | + * @return object |
|
| 46 | + */ |
|
| 47 | + public function markAsRead($id) |
|
| 48 | + { |
|
| 49 | + if ($notification = \Auth::user()->unreadNotifications()->where('id', $id)->first()) { |
|
| 50 | + $notification->markAsRead(); |
|
| 51 | + } |
|
| 52 | + } |
|
| 53 | 53 | |
| 54 | - /** |
|
| 55 | - * Mark all notifications as read. |
|
| 56 | - * |
|
| 57 | - * @return void |
|
| 58 | - */ |
|
| 59 | - public function markAllAsRead() |
|
| 60 | - { |
|
| 61 | - \Auth::user()->unreadNotifications()->update(['read_at' => now()]); |
|
| 62 | - } |
|
| 54 | + /** |
|
| 55 | + * Mark all notifications as read. |
|
| 56 | + * |
|
| 57 | + * @return void |
|
| 58 | + */ |
|
| 59 | + public function markAllAsRead() |
|
| 60 | + { |
|
| 61 | + \Auth::user()->unreadNotifications()->update(['read_at' => now()]); |
|
| 62 | + } |
|
| 63 | 63 | } |
@@ -6,27 +6,27 @@ |
||
| 6 | 6 | |
| 7 | 7 | class AssignRelationsSeeder extends Seeder |
| 8 | 8 | { |
| 9 | - /** |
|
| 10 | - * Run the database seeds. |
|
| 11 | - * |
|
| 12 | - * @return void |
|
| 13 | - */ |
|
| 14 | - public function run() |
|
| 15 | - { |
|
| 16 | - $adminRoleId = \DB::table('roles')->where('name', 'admin')->select('id')->first()->id; |
|
| 9 | + /** |
|
| 10 | + * Run the database seeds. |
|
| 11 | + * |
|
| 12 | + * @return void |
|
| 13 | + */ |
|
| 14 | + public function run() |
|
| 15 | + { |
|
| 16 | + $adminRoleId = \DB::table('roles')->where('name', 'admin')->select('id')->first()->id; |
|
| 17 | 17 | |
| 18 | - /** |
|
| 19 | - * Assign the permissions to the admin role. |
|
| 20 | - */ |
|
| 21 | - \DB::table('permissions')->orderBy('created_at', 'asc')->whereIn('model', ['notification', 'pushNotificationDevice'])->each(function ($permission) use ($adminRoleId) { |
|
| 22 | - \DB::table('permission_role')->insert( |
|
| 23 | - [ |
|
| 24 | - 'permission_id' => $permission->id, |
|
| 25 | - 'role_id' => $adminRoleId, |
|
| 26 | - 'created_at' => \DB::raw('NOW()'), |
|
| 27 | - 'updated_at' => \DB::raw('NOW()') |
|
| 28 | - ] |
|
| 29 | - ); |
|
| 30 | - }); |
|
| 31 | - } |
|
| 18 | + /** |
|
| 19 | + * Assign the permissions to the admin role. |
|
| 20 | + */ |
|
| 21 | + \DB::table('permissions')->orderBy('created_at', 'asc')->whereIn('model', ['notification', 'pushNotificationDevice'])->each(function ($permission) use ($adminRoleId) { |
|
| 22 | + \DB::table('permission_role')->insert( |
|
| 23 | + [ |
|
| 24 | + 'permission_id' => $permission->id, |
|
| 25 | + 'role_id' => $adminRoleId, |
|
| 26 | + 'created_at' => \DB::raw('NOW()'), |
|
| 27 | + 'updated_at' => \DB::raw('NOW()') |
|
| 28 | + ] |
|
| 29 | + ); |
|
| 30 | + }); |
|
| 31 | + } |
|
| 32 | 32 | } |
@@ -18,7 +18,7 @@ |
||
| 18 | 18 | /** |
| 19 | 19 | * Assign the permissions to the admin role. |
| 20 | 20 | */ |
| 21 | - \DB::table('permissions')->orderBy('created_at', 'asc')->whereIn('model', ['notification', 'pushNotificationDevice'])->each(function ($permission) use ($adminRoleId) { |
|
| 21 | + \DB::table('permissions')->orderBy('created_at', 'asc')->whereIn('model', ['notification', 'pushNotificationDevice'])->each(function($permission) use ($adminRoleId) { |
|
| 22 | 22 | \DB::table('permission_role')->insert( |
| 23 | 23 | [ |
| 24 | 24 | 'permission_id' => $permission->id, |
@@ -6,15 +6,15 @@ |
||
| 6 | 6 | |
| 7 | 7 | class ClearDataSeeder extends Seeder |
| 8 | 8 | { |
| 9 | - /** |
|
| 10 | - * Run the database seeds. |
|
| 11 | - * |
|
| 12 | - * @return void |
|
| 13 | - */ |
|
| 14 | - public function run() |
|
| 15 | - { |
|
| 16 | - $permissions = \DB::table('permissions')->whereIn('model', ['notification', 'pushNotificationDevice']); |
|
| 17 | - \DB::table('permission_role')->whereIn('permission_id', $permissions->pluck('id'))->delete(); |
|
| 18 | - $permissions->delete(); |
|
| 19 | - } |
|
| 9 | + /** |
|
| 10 | + * Run the database seeds. |
|
| 11 | + * |
|
| 12 | + * @return void |
|
| 13 | + */ |
|
| 14 | + public function run() |
|
| 15 | + { |
|
| 16 | + $permissions = \DB::table('permissions')->whereIn('model', ['notification', 'pushNotificationDevice']); |
|
| 17 | + \DB::table('permission_role')->whereIn('permission_id', $permissions->pluck('id'))->delete(); |
|
| 18 | + $permissions->delete(); |
|
| 19 | + } |
|
| 20 | 20 | } |
@@ -9,71 +9,71 @@ |
||
| 9 | 9 | |
| 10 | 10 | class NotificationController extends BaseApiController |
| 11 | 11 | { |
| 12 | - /** |
|
| 13 | - * Path of the model resource |
|
| 14 | - * |
|
| 15 | - * @var string |
|
| 16 | - */ |
|
| 17 | - protected $modelResource = 'App\Modules\Notifications\Http\Resources\Notification'; |
|
| 12 | + /** |
|
| 13 | + * Path of the model resource |
|
| 14 | + * |
|
| 15 | + * @var string |
|
| 16 | + */ |
|
| 17 | + protected $modelResource = 'App\Modules\Notifications\Http\Resources\Notification'; |
|
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * List of all route actions that the base api controller |
|
| 21 | - * will skip permissions check for them. |
|
| 22 | - * @var array |
|
| 23 | - */ |
|
| 24 | - protected $skipPermissionCheck = ['markAsRead', 'markAllAsRead', 'index', 'unread']; |
|
| 19 | + /** |
|
| 20 | + * List of all route actions that the base api controller |
|
| 21 | + * will skip permissions check for them. |
|
| 22 | + * @var array |
|
| 23 | + */ |
|
| 24 | + protected $skipPermissionCheck = ['markAsRead', 'markAllAsRead', 'index', 'unread']; |
|
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * Init new object. |
|
| 28 | - * |
|
| 29 | - * @param NotificationService $service |
|
| 30 | - * @return void |
|
| 31 | - */ |
|
| 32 | - public function __construct(NotificationService $service) |
|
| 33 | - { |
|
| 34 | - parent::__construct($service); |
|
| 35 | - } |
|
| 26 | + /** |
|
| 27 | + * Init new object. |
|
| 28 | + * |
|
| 29 | + * @param NotificationService $service |
|
| 30 | + * @return void |
|
| 31 | + */ |
|
| 32 | + public function __construct(NotificationService $service) |
|
| 33 | + { |
|
| 34 | + parent::__construct($service); |
|
| 35 | + } |
|
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * Retrieve all notifications of the logged in user. |
|
| 39 | - * |
|
| 40 | - * @param Request $request |
|
| 41 | - * @return \Illuminate\Http\Response |
|
| 42 | - */ |
|
| 43 | - public function index(Request $request) |
|
| 44 | - { |
|
| 45 | - return $this->modelResource::collection($this->service->my($request->query('perPage'))); |
|
| 46 | - } |
|
| 37 | + /** |
|
| 38 | + * Retrieve all notifications of the logged in user. |
|
| 39 | + * |
|
| 40 | + * @param Request $request |
|
| 41 | + * @return \Illuminate\Http\Response |
|
| 42 | + */ |
|
| 43 | + public function index(Request $request) |
|
| 44 | + { |
|
| 45 | + return $this->modelResource::collection($this->service->my($request->query('perPage'))); |
|
| 46 | + } |
|
| 47 | 47 | |
| 48 | - /** |
|
| 49 | - * Retrieve unread notifications of the logged in user. |
|
| 50 | - * |
|
| 51 | - * @param Request $request |
|
| 52 | - * @return \Illuminate\Http\Response |
|
| 53 | - */ |
|
| 54 | - public function unread(Request $request) |
|
| 55 | - { |
|
| 56 | - return $this->modelResource::collection($this->service->unread($request->query('perPage'))); |
|
| 57 | - } |
|
| 48 | + /** |
|
| 49 | + * Retrieve unread notifications of the logged in user. |
|
| 50 | + * |
|
| 51 | + * @param Request $request |
|
| 52 | + * @return \Illuminate\Http\Response |
|
| 53 | + */ |
|
| 54 | + public function unread(Request $request) |
|
| 55 | + { |
|
| 56 | + return $this->modelResource::collection($this->service->unread($request->query('perPage'))); |
|
| 57 | + } |
|
| 58 | 58 | |
| 59 | - /** |
|
| 60 | - * Mark the notification as read. |
|
| 61 | - * |
|
| 62 | - * @param integer $id Id of the notification. |
|
| 63 | - * @return \Illuminate\Http\Response |
|
| 64 | - */ |
|
| 65 | - public function markAsRead($id) |
|
| 66 | - { |
|
| 67 | - return new GeneralResource($this->service->markAsRead($id)); |
|
| 68 | - } |
|
| 59 | + /** |
|
| 60 | + * Mark the notification as read. |
|
| 61 | + * |
|
| 62 | + * @param integer $id Id of the notification. |
|
| 63 | + * @return \Illuminate\Http\Response |
|
| 64 | + */ |
|
| 65 | + public function markAsRead($id) |
|
| 66 | + { |
|
| 67 | + return new GeneralResource($this->service->markAsRead($id)); |
|
| 68 | + } |
|
| 69 | 69 | |
| 70 | - /** |
|
| 71 | - * Mark all notifications as read. |
|
| 72 | - * |
|
| 73 | - * @return \Illuminate\Http\Response |
|
| 74 | - */ |
|
| 75 | - public function markAllAsRead() |
|
| 76 | - { |
|
| 77 | - return new GeneralResource($this->service->markAllAsRead()); |
|
| 78 | - } |
|
| 70 | + /** |
|
| 71 | + * Mark all notifications as read. |
|
| 72 | + * |
|
| 73 | + * @return \Illuminate\Http\Response |
|
| 74 | + */ |
|
| 75 | + public function markAllAsRead() |
|
| 76 | + { |
|
| 77 | + return new GeneralResource($this->service->markAllAsRead()); |
|
| 78 | + } |
|
| 79 | 79 | } |
@@ -5,71 +5,71 @@ |
||
| 5 | 5 | |
| 6 | 6 | class NotificationService extends BaseService |
| 7 | 7 | { |
| 8 | - /** |
|
| 9 | - * Init new object. |
|
| 10 | - * |
|
| 11 | - * @param NotificationRepository $repo |
|
| 12 | - * @return void |
|
| 13 | - */ |
|
| 14 | - public function __construct(NotificationRepository $repo) |
|
| 15 | - { |
|
| 16 | - parent::__construct($repo); |
|
| 17 | - } |
|
| 8 | + /** |
|
| 9 | + * Init new object. |
|
| 10 | + * |
|
| 11 | + * @param NotificationRepository $repo |
|
| 12 | + * @return void |
|
| 13 | + */ |
|
| 14 | + public function __construct(NotificationRepository $repo) |
|
| 15 | + { |
|
| 16 | + parent::__construct($repo); |
|
| 17 | + } |
|
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * Retrieve all notifications of the logged in user. |
|
| 21 | - * |
|
| 22 | - * @param integer $perPage |
|
| 23 | - * @return Collection |
|
| 24 | - */ |
|
| 25 | - public function my($perPage) |
|
| 26 | - { |
|
| 27 | - return $this->repo->my($perPage); |
|
| 28 | - } |
|
| 19 | + /** |
|
| 20 | + * Retrieve all notifications of the logged in user. |
|
| 21 | + * |
|
| 22 | + * @param integer $perPage |
|
| 23 | + * @return Collection |
|
| 24 | + */ |
|
| 25 | + public function my($perPage) |
|
| 26 | + { |
|
| 27 | + return $this->repo->my($perPage); |
|
| 28 | + } |
|
| 29 | 29 | |
| 30 | - /** |
|
| 31 | - * Retrieve unread notifications of the logged in user. |
|
| 32 | - * |
|
| 33 | - * @param integer $perPage |
|
| 34 | - * @return Collection |
|
| 35 | - */ |
|
| 36 | - public function unread($perPage) |
|
| 37 | - { |
|
| 38 | - return $this->repo->unread($perPage); |
|
| 39 | - } |
|
| 30 | + /** |
|
| 31 | + * Retrieve unread notifications of the logged in user. |
|
| 32 | + * |
|
| 33 | + * @param integer $perPage |
|
| 34 | + * @return Collection |
|
| 35 | + */ |
|
| 36 | + public function unread($perPage) |
|
| 37 | + { |
|
| 38 | + return $this->repo->unread($perPage); |
|
| 39 | + } |
|
| 40 | 40 | |
| 41 | - /** |
|
| 42 | - * Mark the notification as read. |
|
| 43 | - * |
|
| 44 | - * @param integer $id |
|
| 45 | - * @return object |
|
| 46 | - */ |
|
| 47 | - public function markAsRead($id) |
|
| 48 | - { |
|
| 49 | - return $this->repo->markAsRead($id); |
|
| 50 | - } |
|
| 41 | + /** |
|
| 42 | + * Mark the notification as read. |
|
| 43 | + * |
|
| 44 | + * @param integer $id |
|
| 45 | + * @return object |
|
| 46 | + */ |
|
| 47 | + public function markAsRead($id) |
|
| 48 | + { |
|
| 49 | + return $this->repo->markAsRead($id); |
|
| 50 | + } |
|
| 51 | 51 | |
| 52 | - /** |
|
| 53 | - * Mark all notifications as read. |
|
| 54 | - * |
|
| 55 | - * @return void |
|
| 56 | - */ |
|
| 57 | - public function markAllAsRead() |
|
| 58 | - { |
|
| 59 | - return $this->repo->markAllAsRead(); |
|
| 60 | - } |
|
| 52 | + /** |
|
| 53 | + * Mark all notifications as read. |
|
| 54 | + * |
|
| 55 | + * @return void |
|
| 56 | + */ |
|
| 57 | + public function markAllAsRead() |
|
| 58 | + { |
|
| 59 | + return $this->repo->markAllAsRead(); |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | - /** |
|
| 63 | - * Notify th given user with the given notification. |
|
| 64 | - * |
|
| 65 | - * @param collection $users |
|
| 66 | - * @param string $notification |
|
| 67 | - * @param object $notificationData |
|
| 68 | - * @return void |
|
| 69 | - */ |
|
| 70 | - public function notify($users, $notification, $notificationData = false) |
|
| 71 | - { |
|
| 72 | - $notification = 'App\Modules\Notifications\Notifications\\'.$notification; |
|
| 73 | - \Notification::send($users, new $notification($notificationData)); |
|
| 74 | - } |
|
| 62 | + /** |
|
| 63 | + * Notify th given user with the given notification. |
|
| 64 | + * |
|
| 65 | + * @param collection $users |
|
| 66 | + * @param string $notification |
|
| 67 | + * @param object $notificationData |
|
| 68 | + * @return void |
|
| 69 | + */ |
|
| 70 | + public function notify($users, $notification, $notificationData = false) |
|
| 71 | + { |
|
| 72 | + $notification = 'App\Modules\Notifications\Notifications\\'.$notification; |
|
| 73 | + \Notification::send($users, new $notification($notificationData)); |
|
| 74 | + } |
|
| 75 | 75 | } |
@@ -5,39 +5,39 @@ |
||
| 5 | 5 | |
| 6 | 6 | class RoleRepository extends BaseRepository |
| 7 | 7 | { |
| 8 | - /** |
|
| 9 | - * Init new object. |
|
| 10 | - * |
|
| 11 | - * @param Role $model |
|
| 12 | - * @return void |
|
| 13 | - */ |
|
| 14 | - public function __construct(Role $model) |
|
| 15 | - { |
|
| 16 | - parent::__construct($model); |
|
| 17 | - } |
|
| 8 | + /** |
|
| 9 | + * Init new object. |
|
| 10 | + * |
|
| 11 | + * @param Role $model |
|
| 12 | + * @return void |
|
| 13 | + */ |
|
| 14 | + public function __construct(Role $model) |
|
| 15 | + { |
|
| 16 | + parent::__construct($model); |
|
| 17 | + } |
|
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * Detach all permissions from the given role. |
|
| 21 | - * |
|
| 22 | - * @param mixed $role |
|
| 23 | - * @return object |
|
| 24 | - */ |
|
| 25 | - public function detachPermissions($role) |
|
| 26 | - { |
|
| 27 | - $role = ! is_int($role) ? $role : $this->find($role); |
|
| 28 | - $role->permissions()->detach(); |
|
| 29 | - } |
|
| 19 | + /** |
|
| 20 | + * Detach all permissions from the given role. |
|
| 21 | + * |
|
| 22 | + * @param mixed $role |
|
| 23 | + * @return object |
|
| 24 | + */ |
|
| 25 | + public function detachPermissions($role) |
|
| 26 | + { |
|
| 27 | + $role = ! is_int($role) ? $role : $this->find($role); |
|
| 28 | + $role->permissions()->detach(); |
|
| 29 | + } |
|
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * Attach permission ids to the given role. |
|
| 33 | - * |
|
| 34 | - * @param mixed $role |
|
| 35 | - * @param array $permissionIds |
|
| 36 | - * @return object |
|
| 37 | - */ |
|
| 38 | - public function attachPermissions($role, $permissionIds) |
|
| 39 | - { |
|
| 40 | - $role = ! is_int($role) ? $role : $this->find($role); |
|
| 41 | - $role->permissions()->attach($permissionIds); |
|
| 42 | - } |
|
| 31 | + /** |
|
| 32 | + * Attach permission ids to the given role. |
|
| 33 | + * |
|
| 34 | + * @param mixed $role |
|
| 35 | + * @param array $permissionIds |
|
| 36 | + * @return object |
|
| 37 | + */ |
|
| 38 | + public function attachPermissions($role, $permissionIds) |
|
| 39 | + { |
|
| 40 | + $role = ! is_int($role) ? $role : $this->find($role); |
|
| 41 | + $role->permissions()->attach($permissionIds); |
|
| 42 | + } |
|
| 43 | 43 | } |
@@ -8,42 +8,42 @@ |
||
| 8 | 8 | class Role extends Model |
| 9 | 9 | { |
| 10 | 10 | |
| 11 | - use SoftDeletes; |
|
| 12 | - protected $table = 'roles'; |
|
| 13 | - protected $dates = ['created_at', 'updated_at', 'deleted_at']; |
|
| 14 | - protected $hidden = ['deleted_at']; |
|
| 15 | - protected $guarded = ['id']; |
|
| 16 | - protected $fillable = ['name']; |
|
| 17 | - public $searchable = ['name']; |
|
| 18 | - |
|
| 19 | - public function getCreatedAtAttribute($value) |
|
| 20 | - { |
|
| 21 | - return \Carbon\Carbon::parse($value)->tz(\Session::get('time-zone'))->toDateTimeString(); |
|
| 22 | - } |
|
| 23 | - |
|
| 24 | - public function getUpdatedAtAttribute($value) |
|
| 25 | - { |
|
| 26 | - return \Carbon\Carbon::parse($value)->tz(\Session::get('time-zone'))->toDateTimeString(); |
|
| 27 | - } |
|
| 28 | - |
|
| 29 | - public function getDeletedAtAttribute($value) |
|
| 30 | - { |
|
| 31 | - return \Carbon\Carbon::parse($value)->tz(\Session::get('time-zone'))->toDateTimeString(); |
|
| 32 | - } |
|
| 33 | - |
|
| 34 | - public function users() |
|
| 35 | - { |
|
| 36 | - return $this->belongsToMany(AclUser::class, 'role_user', 'role_id', 'user_id')->whereNull('role_user.deleted_at')->withTimestamps(); |
|
| 37 | - } |
|
| 38 | - |
|
| 39 | - public function permissions() |
|
| 40 | - { |
|
| 41 | - return $this->belongsToMany(Permission::class, 'permission_role', 'role_id', 'permission_id')->whereNull('permission_role.deleted_at')->withTimestamps(); |
|
| 42 | - } |
|
| 43 | - |
|
| 44 | - public static function boot() |
|
| 45 | - { |
|
| 46 | - parent::boot(); |
|
| 47 | - Role::observe(\App::make('App\Modules\Roles\ModelObservers\RoleObserver')); |
|
| 48 | - } |
|
| 11 | + use SoftDeletes; |
|
| 12 | + protected $table = 'roles'; |
|
| 13 | + protected $dates = ['created_at', 'updated_at', 'deleted_at']; |
|
| 14 | + protected $hidden = ['deleted_at']; |
|
| 15 | + protected $guarded = ['id']; |
|
| 16 | + protected $fillable = ['name']; |
|
| 17 | + public $searchable = ['name']; |
|
| 18 | + |
|
| 19 | + public function getCreatedAtAttribute($value) |
|
| 20 | + { |
|
| 21 | + return \Carbon\Carbon::parse($value)->tz(\Session::get('time-zone'))->toDateTimeString(); |
|
| 22 | + } |
|
| 23 | + |
|
| 24 | + public function getUpdatedAtAttribute($value) |
|
| 25 | + { |
|
| 26 | + return \Carbon\Carbon::parse($value)->tz(\Session::get('time-zone'))->toDateTimeString(); |
|
| 27 | + } |
|
| 28 | + |
|
| 29 | + public function getDeletedAtAttribute($value) |
|
| 30 | + { |
|
| 31 | + return \Carbon\Carbon::parse($value)->tz(\Session::get('time-zone'))->toDateTimeString(); |
|
| 32 | + } |
|
| 33 | + |
|
| 34 | + public function users() |
|
| 35 | + { |
|
| 36 | + return $this->belongsToMany(AclUser::class, 'role_user', 'role_id', 'user_id')->whereNull('role_user.deleted_at')->withTimestamps(); |
|
| 37 | + } |
|
| 38 | + |
|
| 39 | + public function permissions() |
|
| 40 | + { |
|
| 41 | + return $this->belongsToMany(Permission::class, 'permission_role', 'role_id', 'permission_id')->whereNull('permission_role.deleted_at')->withTimestamps(); |
|
| 42 | + } |
|
| 43 | + |
|
| 44 | + public static function boot() |
|
| 45 | + { |
|
| 46 | + parent::boot(); |
|
| 47 | + Role::observe(\App::make('App\Modules\Roles\ModelObservers\RoleObserver')); |
|
| 48 | + } |
|
| 49 | 49 | } |
@@ -8,80 +8,80 @@ |
||
| 8 | 8 | |
| 9 | 9 | class RolesTableSeeder extends Seeder |
| 10 | 10 | { |
| 11 | - /** |
|
| 12 | - * Run the database seeds. |
|
| 13 | - * |
|
| 14 | - * @return void |
|
| 15 | - */ |
|
| 16 | - public function run() |
|
| 17 | - { |
|
| 18 | - /** |
|
| 19 | - * Assign default users to admin roles. |
|
| 20 | - */ |
|
| 21 | - $adminRoleId = Role::where('name', 'Admin')->select('id')->first()->id;; |
|
| 22 | - $adminUserId = AclUser::where('email', '[email protected]')->select('id')->first()->id; |
|
| 23 | - \DB::table('role_user')->updateOrInsert([ |
|
| 24 | - 'user_id' => $adminUserId, |
|
| 25 | - 'role_id' => $adminRoleId, |
|
| 26 | - ],[]); |
|
| 11 | + /** |
|
| 12 | + * Run the database seeds. |
|
| 13 | + * |
|
| 14 | + * @return void |
|
| 15 | + */ |
|
| 16 | + public function run() |
|
| 17 | + { |
|
| 18 | + /** |
|
| 19 | + * Assign default users to admin roles. |
|
| 20 | + */ |
|
| 21 | + $adminRoleId = Role::where('name', 'Admin')->select('id')->first()->id;; |
|
| 22 | + $adminUserId = AclUser::where('email', '[email protected]')->select('id')->first()->id; |
|
| 23 | + \DB::table('role_user')->updateOrInsert([ |
|
| 24 | + 'user_id' => $adminUserId, |
|
| 25 | + 'role_id' => $adminRoleId, |
|
| 26 | + ],[]); |
|
| 27 | 27 | |
| 28 | - /** |
|
| 29 | - * Insert the permissions related to roles table. |
|
| 30 | - */ |
|
| 31 | - \DB::table('permissions')->insert( |
|
| 32 | - [ |
|
| 33 | - /** |
|
| 34 | - * Roles model permissions. |
|
| 35 | - */ |
|
| 36 | - [ |
|
| 37 | - 'name' => 'index', |
|
| 38 | - 'model' => 'role', |
|
| 39 | - 'created_at' => \DB::raw('NOW()'), |
|
| 40 | - 'updated_at' => \DB::raw('NOW()') |
|
| 41 | - ], |
|
| 42 | - [ |
|
| 43 | - 'name' => 'find', |
|
| 44 | - 'model' => 'role', |
|
| 45 | - 'created_at' => \DB::raw('NOW()'), |
|
| 46 | - 'updated_at' => \DB::raw('NOW()') |
|
| 47 | - ], |
|
| 48 | - [ |
|
| 49 | - 'name' => 'insert', |
|
| 50 | - 'model' => 'role', |
|
| 51 | - 'created_at' => \DB::raw('NOW()'), |
|
| 52 | - 'updated_at' => \DB::raw('NOW()') |
|
| 53 | - ], |
|
| 54 | - [ |
|
| 55 | - 'name' => 'update', |
|
| 56 | - 'model' => 'role', |
|
| 57 | - 'created_at' => \DB::raw('NOW()'), |
|
| 58 | - 'updated_at' => \DB::raw('NOW()') |
|
| 59 | - ], |
|
| 60 | - [ |
|
| 61 | - 'name' => 'delete', |
|
| 62 | - 'model' => 'role', |
|
| 63 | - 'created_at' => \DB::raw('NOW()'), |
|
| 64 | - 'updated_at' => \DB::raw('NOW()') |
|
| 65 | - ], |
|
| 66 | - [ |
|
| 67 | - 'name' => 'deleted', |
|
| 68 | - 'model' => 'role', |
|
| 69 | - 'created_at' => \DB::raw('NOW()'), |
|
| 70 | - 'updated_at' => \DB::raw('NOW()') |
|
| 71 | - ], |
|
| 72 | - [ |
|
| 73 | - 'name' => 'restore', |
|
| 74 | - 'model' => 'role', |
|
| 75 | - 'created_at' => \DB::raw('NOW()'), |
|
| 76 | - 'updated_at' => \DB::raw('NOW()') |
|
| 77 | - ], |
|
| 78 | - [ |
|
| 79 | - 'name' => 'assignPermissions', |
|
| 80 | - 'model' => 'role', |
|
| 81 | - 'created_at' => \DB::raw('NOW()'), |
|
| 82 | - 'updated_at' => \DB::raw('NOW()') |
|
| 83 | - ], |
|
| 84 | - ] |
|
| 85 | - ); |
|
| 86 | - } |
|
| 28 | + /** |
|
| 29 | + * Insert the permissions related to roles table. |
|
| 30 | + */ |
|
| 31 | + \DB::table('permissions')->insert( |
|
| 32 | + [ |
|
| 33 | + /** |
|
| 34 | + * Roles model permissions. |
|
| 35 | + */ |
|
| 36 | + [ |
|
| 37 | + 'name' => 'index', |
|
| 38 | + 'model' => 'role', |
|
| 39 | + 'created_at' => \DB::raw('NOW()'), |
|
| 40 | + 'updated_at' => \DB::raw('NOW()') |
|
| 41 | + ], |
|
| 42 | + [ |
|
| 43 | + 'name' => 'find', |
|
| 44 | + 'model' => 'role', |
|
| 45 | + 'created_at' => \DB::raw('NOW()'), |
|
| 46 | + 'updated_at' => \DB::raw('NOW()') |
|
| 47 | + ], |
|
| 48 | + [ |
|
| 49 | + 'name' => 'insert', |
|
| 50 | + 'model' => 'role', |
|
| 51 | + 'created_at' => \DB::raw('NOW()'), |
|
| 52 | + 'updated_at' => \DB::raw('NOW()') |
|
| 53 | + ], |
|
| 54 | + [ |
|
| 55 | + 'name' => 'update', |
|
| 56 | + 'model' => 'role', |
|
| 57 | + 'created_at' => \DB::raw('NOW()'), |
|
| 58 | + 'updated_at' => \DB::raw('NOW()') |
|
| 59 | + ], |
|
| 60 | + [ |
|
| 61 | + 'name' => 'delete', |
|
| 62 | + 'model' => 'role', |
|
| 63 | + 'created_at' => \DB::raw('NOW()'), |
|
| 64 | + 'updated_at' => \DB::raw('NOW()') |
|
| 65 | + ], |
|
| 66 | + [ |
|
| 67 | + 'name' => 'deleted', |
|
| 68 | + 'model' => 'role', |
|
| 69 | + 'created_at' => \DB::raw('NOW()'), |
|
| 70 | + 'updated_at' => \DB::raw('NOW()') |
|
| 71 | + ], |
|
| 72 | + [ |
|
| 73 | + 'name' => 'restore', |
|
| 74 | + 'model' => 'role', |
|
| 75 | + 'created_at' => \DB::raw('NOW()'), |
|
| 76 | + 'updated_at' => \DB::raw('NOW()') |
|
| 77 | + ], |
|
| 78 | + [ |
|
| 79 | + 'name' => 'assignPermissions', |
|
| 80 | + 'model' => 'role', |
|
| 81 | + 'created_at' => \DB::raw('NOW()'), |
|
| 82 | + 'updated_at' => \DB::raw('NOW()') |
|
| 83 | + ], |
|
| 84 | + ] |
|
| 85 | + ); |
|
| 86 | + } |
|
| 87 | 87 | } |
@@ -18,12 +18,12 @@ |
||
| 18 | 18 | /** |
| 19 | 19 | * Assign default users to admin roles. |
| 20 | 20 | */ |
| 21 | - $adminRoleId = Role::where('name', 'Admin')->select('id')->first()->id;; |
|
| 21 | + $adminRoleId = Role::where('name', 'Admin')->select('id')->first()->id; ; |
|
| 22 | 22 | $adminUserId = AclUser::where('email', '[email protected]')->select('id')->first()->id; |
| 23 | 23 | \DB::table('role_user')->updateOrInsert([ |
| 24 | 24 | 'user_id' => $adminUserId, |
| 25 | 25 | 'role_id' => $adminRoleId, |
| 26 | - ],[]); |
|
| 26 | + ], []); |
|
| 27 | 27 | |
| 28 | 28 | /** |
| 29 | 29 | * Insert the permissions related to roles table. |