I have an array in which each Section holds information about its status and route name:
$sections = array(
'Section_1' => array(
'status' => 1,
'route' => 'section1.route'
),
'Section_2' => array(
'status' => 0,
'route' => 'section2.route'
),
'Section_3' => array(
'status' => 1,
'route' => 'section3.route'
)
);
I'm trying to loop through it to create a HTML list.
I tried this (1):
@foreach ($sections as $dataName => $details)
<li>
<a href="{{ URL::route($details['route']) }}">{{ $dataName }}</a>
</li>
@endforeach
This (2):
@foreach ($sections as $dataName => $details)
<li>
<?php $routeName = $details['route']; ?>
<a href="{{ URL::route($routeName) }}">{{{ $dataName }}}</a>
</li>
@endforeach
And this (3):
@foreach ($sections as $dataName => $details)
<li>
<?php $routeName = URL::route($details['route']); ?>
<a href="<?php echo $routeName; ?>">{{{ $dataName }}}</a>
</li>
@endforeach
All of the above throw the same error:
Route [] not defined.
InvalidArgumentException("Route [{$name}] not defined.")
All the routes in the array exist - checked them for typos and so on. I have a feeling this might be something tiny but I don't see what. Any ideas?
PS. I'm aware I can store full routes in the array, like 'route' => URL::route('section1.route')
etc. But what is wrong with the pieces of code above?
EDIT: Sample route
Route::get('user/show/section1',
array(
'before' => 'auth',
'uses' => 'UserController@showSection1',
'as' => 'section1.route'
)
);
I'm using named routes.