Example #1
0
 public function access()
 {
     $paths = '';
     for ($i = 0; $i < 2; $i++) {
         if (isset($this->path[$i])) {
             $paths .= $this->path[$i] . '/';
         }
     }
     $path = rtrim($paths, '/');
     $menu = data_menu_user::whereIn('id_level', \Me::level())->get();
     $access = [];
     foreach ($menu as $val) {
         $access[] = $val->id_menu;
     }
     $slug = data_menu::whereIn('id_menu', $access)->select('slug')->get();
     $slugs = [];
     foreach ($slug as $aces) {
         $slugs[] = $aces->slug;
     }
     if (!empty(\Request::path())) {
         $cek = empty($path) ? 0 : data_menu::whereSlug($path)->count();
         if (!empty($path) && !in_array($path, $slugs) && $cek > 0) {
             return ['return' => false];
         }
         $cek = empty($path) ? 0 : data_menu::whereSlug($path)->count();
         if (!empty($path) && !in_array($path, $slugs) && $cek > 0) {
             return ['return' => false];
         }
     }
     return ['return' => true];
 }