I'm new to Laravel and Blade and have been trying to create a view using Illuminate/Html
.
I have a table called service_locations(location_id, location_area)
.
Using the above table I'm trying to populate the below dropdown list:
<div class="form-group">
{!! Form::label('location', 'Location:') !!}
{!! Form::select('location', array(
@foreach($locations as $local)
'{{ $local->location_id }}' => '{{ $local->location_area }}',
@endforeach
), null, ['class' => 'form-control']) !!}
</div>
But as I attempt to do so, I am getting the following error in the second-last line (), null, ['class' => 'form-control']) !!}
):
syntax error, unexpected '<', expecting ')'
I am not able to figure out the issue with the above code.
Edit 1 Here's what my controller looks like:
<?php namespace App\Http\Controllers;
use App\service_location;
use App\service_type;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
class PagesController extends Controller {
public function index()
{
$locations = service_location::all();
$services = service_type::all();
return view('home.index', compact('locations','services'));
}
}
you cant use blade that way,
but you can achieve the same result with
{!! Form::select('location', $locations->lists('id','location_area'), null, ['class' => 'form-control']); !!}