12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- <?php
-
- namespace App\Model;
-
- use Jenssegers\Mongodb\Eloquent\Model as Eloquent;
- use Jenssegers\Mongodb\Eloquent\SoftDeletes;
-
- class StaffDetail extends Eloquent
- {
- use SoftDeletes;
- //
- protected $connection = 'mongodb';
- protected $collection = 'staff_detail';
-
- protected $guarded = ['_id'];
-
- public function staff() {
- return $this->belongsTo('App\Model\Staff','_id','_id');
- }
-
- public function roles()
- {
- return $this->belongsToMany('App\Model\Module\Roles');
- }
-
- public function department()
- {
- return $this->belongsToMany('App\Model\Module\Department');
- }
-
- /**
- * @param string|array $roles
- */
- public function authorizeRoles($roles)
- {
- if (is_array($roles)) {
- return $this->hasAnyRole($roles) ||
- abort(401, 'This action is unauthorized.');
- }
- return $this->hasRole($roles) ||
- abort(401, 'This action is unauthorized.');
- }
-
- /**
- * Check multiple roles
- * @param array $roles
- */
- public function hasAnyRole($roles)
- {
- return null !== $this->roles()->whereIn('name', $roles)->first();
- }
-
- /**
- * Check one role
- * @param string $role
- */
- public function hasRole($role)
- {
- return null !== $this->roles()->where('name', $role)->first();
- }
- }
|