Kawash Haidari
Kawash Haidari

Reputation: 33

How can I pass select list value to a variable in php laravel?

I Have the following piece of code that works perfectly.

<div id="priceBloc" class="form-group <?php echo (isset($errors) and $errors->has('price')) ? 'has-error' : ''; ?>">
    <label class="col-md-3 control-label" for="price">{{ t('Price') }}</label>
    <div class="col-md-4">
        <div class="input-group">
            @if ($country->get('currency')->in_left == 1)
                <span class="input-group-addon">{{ $country->get('currency')->symbol }}</span>
            @endif
            <input id="price" name="price" class="form-control" placeholder="{{ t('e.i. 15000') }}" type="text" value="{{ old('price') }}">
            @if ($country->get('currency')->in_left == 0)
                <span class="input-group-addon">{{ $country->get('currency')->symbol }}</span>
            @endif
        </div>
    </div>
    <div class="col-md-4">
        <div class="checkbox">
            <label>
                <input id="negotiable" name="negotiable" type="checkbox" value="1" {{ (old('negotiable')=='1') ? 'checked="checked"' : '' }}>
                {{ t('Negotiable') }}
            </label>
        </div>
    </div>
</div>

However I need a select list item for price symbol so the user can select between two different currency like AUD and USD.

Is there any way I can do this please help me as I am very new to Php Laravel.

Upvotes: 1

Views: 147

Answers (1)

kerrin
kerrin

Reputation: 3452

In your controller, get the list of currencies and pass this to your view:

$currencyList = Country::all()->sortBy('currency', SORT_NATURAL | SORT_FLAG_CASE)->pluck('name', 'id');

Then add the select field to your form:

<div class="form-group">
    {{ Form::label('Currency') }}
    {{ Form::select('currency', $currencyList, null, array('class'=>'form-control', 'placeholder'=>'Select currency')) }}
</div>

Upvotes: 1

Related Questions