Dashboard sipadu mbip
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. namespace App\Model;
  3. use Jenssegers\Mongodb\Eloquent\Model as Eloquent;
  4. use Jenssegers\Mongodb\Eloquent\SoftDeletes;
  5. class StaffDetail extends Eloquent
  6. {
  7. use SoftDeletes;
  8. //
  9. protected $connection = 'mongodb';
  10. protected $collection = 'staff_detail';
  11. protected $guarded = ['_id'];
  12. public function staff() {
  13. return $this->belongsTo('App\Model\Staff','_id','_id');
  14. }
  15. public function roles()
  16. {
  17. return $this->belongsToMany('App\Model\Module\Roles');
  18. }
  19. public function department()
  20. {
  21. return $this->belongsToMany('App\Model\Module\Department');
  22. }
  23. public function reportenforcer() {
  24. return $this->hasMany('App\Model\Module\ReportEnforcer');
  25. }
  26. /**
  27. * @param string|array $roles
  28. */
  29. public function authorizeRoles($roles)
  30. {
  31. if (is_array($roles)) {
  32. return $this->hasAnyRole($roles) ||
  33. abort(401, 'This action is unauthorized.');
  34. }
  35. return $this->hasRole($roles) ||
  36. abort(401, 'This action is unauthorized.');
  37. }
  38. /**
  39. * Check multiple roles
  40. * @param array $roles
  41. */
  42. public function hasAnyRole($roles)
  43. {
  44. return null !== $this->roles()->whereIn('name', $roles)->first();
  45. }
  46. /**
  47. * Check one role
  48. * @param string $role
  49. */
  50. public function hasRole($role)
  51. {
  52. return null !== $this->roles()->where('name', $role)->first();
  53. }
  54. }