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.

44 lines
984 B

8 years ago
  1. <?php
  2. namespace App\Http\Model;
  3. use Illuminate\Database\Eloquent\Model;
  4. class Menu extends Model
  5. {
  6. protected $table = 'menu';
  7. public $timestamps = false;
  8. protected $guarded = []; //$guarded包含你不想被赋值的字段数组。
  9. //获取后台管理员所具有权限的菜单列表
  10. public static function getPermissionsMenu($role_id, $pid=0, $pad=0)
  11. {
  12. $res = [];
  13. $where['access.role_id'] = $role_id;
  14. $where['menu.pid'] = $pid;
  15. $where["menu.status"] = 1;
  16. $menu = object_to_array(\DB::table('menu')
  17. ->join('access', 'access.menu_id', '=', 'menu.id')
  18. ->select('menu.*', 'access.role_id')
  19. ->where($where)
  20. ->orderBy('listorder', 'asc')
  21. ->get());
  22. if($menu)
  23. {
  24. foreach($menu as $row)
  25. {
  26. $row['deep'] = $pad;
  27. if($PermissionsMenu = self::getPermissionsMenu($role_id, $row['id'], $pad+1))
  28. {
  29. $row['child'] = $PermissionsMenu;
  30. }
  31. $res[] = $row;
  32. }
  33. }
  34. return $res;
  35. }
  36. }