Dashboard sipadu mbip
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

StaffDetail.php 1.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. /**
  24. * @param string|array $roles
  25. */
  26. public function authorizeRoles($roles)
  27. {
  28. if (is_array($roles)) {
  29. return $this->hasAnyRole($roles) ||
  30. abort(401, 'This action is unauthorized.');
  31. }
  32. return $this->hasRole($roles) ||
  33. abort(401, 'This action is unauthorized.');
  34. }
  35. /**
  36. * Check multiple roles
  37. * @param array $roles
  38. */
  39. public function hasAnyRole($roles)
  40. {
  41. return null !== $this->roles()->whereIn('name', $roles)->first();
  42. }
  43. /**
  44. * Check one role
  45. * @param string $role
  46. */
  47. public function hasRole($role)
  48. {
  49. return null !== $this->roles()->where('name', $role)->first();
  50. }
  51. }