How to show selected value from database in dropdown using Laravel?

Today, We want to share with you laravel dropdown from database.In this post we will show you how to show select box with selected option dynamically in laravel, hear for create dropdown from database value selected in laravel. we will give you demo and example for implement.In this post, we will learn about Select DropDowns Option Selected In Laravel with an example.

Laravel Select Dropdown From Database Example

Question: how to retrieve data from database whenever select in drop down list in laravel?

Laravel Controller Code

/**
* Show records
*
* @return \Illuminate\Http\Response
*/

public function dropDownShow(Request $request)
{

   $products = Product::pluck('name', 'id');
   $selectedID = 2;
   return view('products.edit', compact('id', 'products'));

}

Example 1 : Using Form

{!! Form::Label('product', 'Product:') !!} {!! Form::select('product_id', $products, $selectedID, ['class' => 'form-control']) !!}

Example 2 : Without Using Form


I hope you get an idea about create dynamic select box with Form class.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Leave a Comment