1

Route File:-

Route::get('/',function()
{
 $menuitem = Menuitem::all(); 
 return VIEW::make('index',$menuitem); 
});

index.blade.php:-

@foreach($menuitem as $item)
 {{$item['item_link']}} 
@endforeach

I am getting an error Undefined variable $menuitem in index.blade.php.

3 Answers 3

1

Try

Route::get('/',function()
{
    $menuitem = Menuitem::all(); 
    return View::make('index')->with('menuItem', $menuItem); 
}
Sign up to request clarification or add additional context in comments.

1 Comment

Finally I can access array in view . Thanks for your support
0

View::make accepts an array for the second parameter.

public View make(string $view, array $data = array(), array $mergeData = array())

So it should be:

Route::get('/',function()
{
  $menuitem = Menuitem::all();

  $data = array(
            'menuitemKey' => $menuitem
          );

  return View::make('index', $data); 
}

Then you can access it like:

@foreach($menuitemKey as $item)
  {{$item['item_link']}} 
@endforeach

Comments

0

This worked for me.

'Route('/',function(){
$myarray = Menuitem::all();
return View::make('myview')->with('data',$myarray);
})'

myview.blade.php

'@for($i=0;$i<sizeof($data),$i++)
 {{$data[$i]['item']}}
  @endfor'

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.