我们如何全局设置菜单列表

时间:2015-08-10 12:59:05

标签: php laravel laravel-5

最初我必须附上每个动作: -

这里我们首先获取菜单细节,然后传入视图部分。

Class ManageadministratorController extends Controller {
    public $data_menu;
    public function __construct() {
        $this->middleware('auth');
        $obj = new General;
        $this->data_menu=$obj->displaymenu();
    }
   public function index()
   {     
     $obj = new General;
     $permission = $obj->checkViewPermission("manageadministrator"); 
     $query= Adminlogin::get();
     return View::Make('admin.manageadministrator.manage',array('record'=>$query,'menu_list'=>$this->data_menu));    
   }
   function add()
   {
      return View::Make('admin.manageadministrator.add',array('menu_list'=>$this->data_menu)); 
   }
}

1 个答案:

答案 0 :(得分:0)

您可以注册自定义服务提供商或使用AppServiceProvider:

public function boot()
{
    $obj = new General;
    $data_menu = $obj->displaymenu();
    view()->composer('admin.manageadministrator', function($view) {
        $view->with('menu_list', $data_menu);
    });
}

或使用专门的课程:

// app/Providers/AppServiceProvider.php
public function boot()
{
    view()->composer('admin.manageadministrator', 'App\Http\Composers\MasterComposer');
}



// app/Http/Composers/MasterComposer.php
use Illuminate\Contracts\View\View;

class MasterComposer {

    public function compose(View $view)
    {
        $obj = new General;
        $data_menu = $obj->displaymenu();
        $view->with('menu_list', $data_menu);
    }
}