App\Http\Controllers\MenusController::index PHP Method

index() public method

public index ( ) : Illuminate\View\View
return Illuminate\View\View
    public function index()
    {
        // Log action by user.
        Audit::log(Auth::user()->id, trans('admin/menu-builder/menu-builder.audit-log.category'), trans('admin/menu-builder/menu-builder.audit-log.msg-index'));
        // Set page title and description.
        $page_title = trans('admin/menu-builder/menu-builder.page.index.title');
        $page_description = trans('admin/menu-builder/menu-builder.page.index.description');
        // Load all menus ordered by Parent (asc), Position (asc), Label (asc) and finally ID (asc).
        $menus = Menu::orderBy('parent_id', 'ASC')->orderBy('position', 'ASC')->orderBy('label', 'ASC')->orderBy('id', 'ASC')->get();
        // Convert menu query result to JSON for JSTree
        $menusJson = $this->menusOrmToJsTreeJson($menus);
        // List label and id of all menus ordered by Label (asc).
        $parents = Menu::where('separator', '0')->orderBy('label', 'ASC')->orderBy('id', 'ASC')->get()->lists('label', 'id');
        // Convert to array.
        $parents = $parents->toArray();
        // List name and id of all routes ordered by Name (asc).
        $routes = Route::whereNotNull('name')->orderBy('name', 'ASC')->get()->lists('name', 'id');
        // Convert to array.
        $routes = $routes->toArray();
        // Add a blank option at the top.
        $routes = array('blank' => '') + $routes;
        // List display name and id of all permissions ordered by Name (asc).
        $permissions = Permission::orderBy('name', 'ASC')->get()->lists('display_name', 'id');
        // Convert to array.
        $permissions = $permissions->toArray();
        // Add a blank option at the top.
        $permissions = array('blank' => '') + $permissions;
        // Return view
        return view('admin.menus.index', compact('menus', 'menusJson', 'parents', 'routes', 'permissions', 'page_title', 'page_description'));
    }