0

I am trying to display the currencies in the dropdown menu but I need the data with a value of default=1 to be selected. upon searching, i found a sample and tried to applied it to my controller, here's what I came up,

$currencies = \DB::table('currencies')->where('default', 1)->lists('acronym');

it doesn't work. the error message said

Call to undefined method Illuminate\Database\Query\Builder::lists()

also I read a comment that the list() is already obsolete in laravel.

how can I achieve this?

here's from my create function in controller

public function create()
{
    $currencies = \DB::table('currencies')->where('default', 1)->lists('acronym');
    return view ('orders.create')->with('currencies', $currencies);
}

here's from create blade

{{ Form::select('currency_id', $currencies, Input::old('currency_id'),null, ['class' => 'form-control input-lg','required']) }}

thank you so much in advance!

1 Answer 1

1

Try using ->pluck(),

$currencies = \DB::table('currencies')->pluck('currency_name','id');

// In blade
{{ Form::select('currency_id', $currencies, null, ['class' => 'form-control input-lg','required']) }}

Read more about pluck here.

Sign up to request clarification or add additional context in comments.

6 Comments

thanks @ViperTecPro! may I ask how am I going to display the data in the select field with the value of default=1 being selected?
Don't worry about that laravel collective does that for you just remove Input::old('currency_id') from the select,
it does show the data but only the value with default=1. what I would like to do is to show also the other data. which means the data with value of default=0. how can I make it possible? thanks!
If you want both default 0 and 1 then remove where clause from the query
yes I removed it already. so currently all the data is now in the dropdown. how can i make the default=1 being selected?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.