0% found this document useful (0 votes)
149 views

How To Create Dynamic Dropdown List Using Laravel

This document provides steps to create a dynamic dropdown list using Laravel. It involves: 1. Creating a model to retrieve data from the database table 2. Creating a provider to share the model data to views 3. Registering the provider in the app configuration file 4. Looping through the shared data in views to display option values from the model

Uploaded by

Wahyu Oh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
149 views

How To Create Dynamic Dropdown List Using Laravel

This document provides steps to create a dynamic dropdown list using Laravel. It involves: 1. Creating a model to retrieve data from the database table 2. Creating a provider to share the model data to views 3. Registering the provider in the app configuration file 4. Looping through the shared data in views to display option values from the model

Uploaded by

Wahyu Oh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

1 Shinerweb Technologies www.shinerweb.

com

How to create Dynamic Dropdown List using


laravel

Let’s see output first Okay this all value


coming from database

Step 1 : create model


<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Yourmodelname extends Model

protected $table = 'your_table_name';

Go to app folder and create model


I need to display all this class name in
dropdown
www.shinerweb.com

Step 2 : Create Provider


2 Shinerweb Technologies www.shinerweb.com

Go to provider folder and copy past below


code
<?php

namespace App\Providers;

use App\Modelname; // write model name here

use Illuminate\Support\ServiceProvider;

class Providername extends ServiceProvider

public function boot()

view()->composer('*',function($view){

$view->with('arrayname', Modelname::all());

});

Step 3 : Register your provide which we are


www.shinerweb.com

created

Go to config/app.php and add below line


App\Providers\Providername::class,
3 Shinerweb Technologies www.shinerweb.com

Step 4 : Now you can used Array which we


created in provider

Open your view and copy past this code

@foreach ($arrayname as $data)

<option value="{{ $data->id }}" >{{ $data->key_name }}</option>

@endforeach

Okay it’s work pretty well

If you need above code please drop your


email id we will share code on your
email
www.shinerweb.com

Thank you for watching

Subscribe our channel @shinerweb

You might also like