I'm trying to generate a simple drop-down list (Laravel 5) where the value of each option is the ID of my businesslocations table rows, and the displayed text is composed of multiple columns data (address_1, address_2, city) taken from each row.
In my controller
public function create()
{
$businesslocations = Businesslocation::where('businesslocations.business_id', '=', \Auth::user()->business_id)->get();
return view('client.create')->with(['businesslocations' => $businesslocations]);
}
Here's where i'm at in create.blade.php
{!! Form::label('businesslocation_id', 'Business location:') !!}
@foreach($businesslocations as $key => $businesslocation)
{!! Form::select('businesslocation_id', $businesslocations, null, ['class' => 'form-control']) !!}
@endforeach
It displays with value 0 :
<label for="businesslocation_id">Business location:</label>
<select class="form-control" id="businesslocation_id" name="businesslocation_id"><option value="0">{"id":"3","business_id":"7","address_1":" ","address_2":" ","city":" ","created_at":"2015-07-13 15:59:19","updated_at":"2015-07-13 15:59:19"}</option></select>
I'm looking for something like this value="id" and display text="address_1 address_2 city" for each option. Not sure about the syntax to get there.
<label for="businesslocation_id">Business location:</label>
<select class="form-control" id="businesslocation_id" name="businesslocation_id"><option value="1">Business location 1 - address_1 address_2 city</option><option value="2" selected="selected">Business location 2 - address_1 address_2 city</option></select>