I'm new at Laravel. and i got a little problem with view.
here is my controller
public function main_menu()
{
$mainmenus = DB::table('main_menus')->get();
$subs = $mainmenus;
foreach ($subs as $key => $value)
{
$subs[$key] = DB::table('sub_menus')
->where('parent_id', '=' , $value->main_id)
->get();
}
$products = DB::table('sub_menus')->get();
foreach ($products as $key => $value) {
$products[$key] = DB::table('products')
-> where('product_parent', '=', $value->sub_id)
->get();
}
$data = array("mainmenus" => $mainmenus,
"submenus" => $subs,
"productmenus" => $products);
return View::make('layouts/nav', $data);
}
and here is my layouts/nav.blade.php
@extends('layouts_index')
@section('nav')
<div class="nav">
<nav class="navbar">
<ul id="menu">
<li class="active"><a href="index" class="drop"><i class="icon-home icon-small"> </i>Home</a></li>
@foreach ($mainmenus as $key=>$mainmenu)
<li>
<a href="menu/{{ $mainmenu->main_id }}" class="drop">
<i class="icon-{{ $mainmenu->main_icon }} icon-small"></i>{{ $mainmenu->main_title_id }}</a>
@if( $mainmenu->main_desc_id != "")
<div class="dropdown_3columns">
<div class="col_4">
<h3><i class="icon-{{ $mainmenu->main_icon }} icon-large"></i>{{ $mainmenu->main_title_id }}</h3>
<h4>{{ $mainmenu->main_desc_id }}</h4>
</div>
@foreach ($submenus[$key] as $key=>$submenu)
<div class="col_1">
<a href="" ><h5><i class="icon-small icon-bookmark"></i>{{ $submenu->sub_title_id }}</h5></a>
<ul>
@foreach ($productmenus[$key] as $productmenu)
<li>
<a href="" ><i class="icon-small icon-th-large"></i>{{ $productmenu->product_title_id }}</a>
</li>
@endforeach
</ul>
</div>
@endforeach
</div>
@endif
</li>
@endforeach
<li class="last"><a href="#" class="drop "><i class="icon-pencil icon-small"></i>Tentang Kami</a></li>
</ul>
</nav>
</div>
@stop
my routes:
Route::get('/', 'ShowsController@index');
when i try to run the index.blade.php it says: Undefined variable: mainmenus (View: C:\xampp\htdocs\mestika\app\views\layouts av.blade.php) (View: C:\xampp\htdocs\mestika\app\views\layouts av.blade.php) (View: C:\xampp\htdocs\mestika\app\views\layouts av.blade.php)
what i want to do is i want to show main_menu at every view pages. i've tried changed view::make to view::share. but no luck. is there anything i miss at here?