Have you tried a search? https://laracasts.com/search?q=Dropdown&q-where=lessons
Nov 15, 2015
4
Level 7
Illuminate\Html Form Country Drop down
Im creating a form using Illuminate\Html. So i got two questions about it is Illuminate html better? Second how can i create the drop down?
<div class="form-group">
{!! Form::label('Country', 'Country:') !!}
@foreach($countries::all() as $country)
{!! Form::select('country', array($country))!!}
@endforeach
</div>
<!-- Country Form Input -->
<div class="form-group">
{!! Form::label('Country', 'Country:') !!}
{!! Form::select('country', $country) !!}
</div>
the above both don't work
@inject('countries', 'App\Http\Utilities\Country')
@extends('app')
@section('content')
<h1>Contact</h1>
<hr/>
{!! Form::open() !!}
<!-- Firstname Form Input -->
<div class="form-group">
{!! Form::label('firstname', 'Firstname:') !!}
{!! Form::text('firstname', null, ['class' => 'form-control']) !!}
</div>
<!-- Lastname Form Input -->
<div class="form-group">
{!! Form::label('lastname', 'Lastname:') !!}
{!! Form::text('lastname', null, ['class' => 'form-control']) !!}
</div>
<!-- Email Form Input -->
<div class="form-group">
{!! Form::label('email', 'Email:') !!}
{!! Form::text('email', null, ['class' => 'form-control']) !!}
</div>
<!-- Street Form Input -->
<div class="form-group">
{!! Form::label('street', 'Street:') !!}
{!! Form::text('street', null, ['class' => 'form-control']) !!}
</div>
<!-- City Form Input -->
<div class="form-group">
{!! Form::label('City', 'City:') !!}
{!! Form::text('City', null, ['class' => 'form-control']) !!}
</div>
<!-- Zip Form Input -->
<div class="form-group">
{!! Form::label('zip', 'Zip/Postal Code:') !!}
{!! Form::text('zip', null, ['class' => 'form-control']) !!}
</div>
<!-- Country Form Input -->
<div class="form-group">
{!! Form::label('Country', 'Country:') !!}
{!! Form::select('country', $countries ) !!}
</div>
<!-- State Form Input -->
<div class="form-group">
{!! Form::label('state', 'State:') !!}
{!! Form::text('state', null, ['class' => 'form-control']) !!}
</div>
<!-- Add Contact Form Input -->
<div class="form-group">
{!! Form::submit('Add Contact', ['class' => 'btn btn-primary form-control']) !!}
</div>
{!! Form::close() !!}
@stop
<?php
namespace App\Http\Utilities;
class Country{
protected static $countries = [
"United States" => "us",
"Afghanistan" => "af",
"Albania" => "al",
"Algeria" => "dz",
"American Samoa" => "as",
"Andorra" => "ad",
"Angola" => "ad",
"Anguilla" => "ai",
"Antarctica" => "aq",
"Antigua and Barbuda" => "ag",
"Argentina" => "ar",
"Armenia" => "am",
"Aruba" => "aw",
"Australia" => "au",
"Austria" => "at",
"Azerbaijan" => "az",
"Bahamas" => "bs",
"Bahrain" => "bh",
"Bangladesh" => "bd",
"Barbados" => "bb",
"Belarus" => "by",
"Belgium" => "be",
"Belize" => "bz",
"Benin" => "bj",
"Virgin Islands (British)" => "vg",
"Virgin Islands (U.S.)" => "vi",
"Wallis and Futuna Islands" => "wf",
"Western Sahara" => "eh",
"Yemen" => "ye",
"Serbia" => "yu",
"Zambia" => "zm",
"Zimbabwe" => "zw"
];
public static function all()
{
return array_keys(static::$countries);
}
}
Please or to participate in this conversation.