databaselaravelmultiple-tablessinglepagepopulation

Laravel population drop down box from multiple tables in a single view


I want to populate drop down box with data from two database tables in a single view.

So, I have two drop down boxes and I want to populate with data from two tables in order to select two different data.

CarsController.php code:

public function getCarList()
{
    $carsList = Car::all();
    return view('adminlte::books', compact('carsList'));
}

ClientsController.php code:

public function getClientList()
 {
    $clientsList = Client::all();
    return view('adminlte::books', compact('clientsList'));
 }

book.blade.php code:

<select name="color" id="clientName" class="form-control clientname">
   <option value="0" diabled="true" selected="true">-Select-</option>
   @foreach($clientsList as $cli)
       <option value="{{$cli->id}}">{{$cli->name}}</option>
   @endforeach

 </select>

 <select name="color" id="carName" class="form-control carname">
    <option value="0" diabled="true" selected="true">-Select-</option>
    @foreach($carsList as $carli)
       <option value="{{$carli->id}}">{{$carli->name}}</option>
    @endforeach
  </select>

When I remove one of these select boxes in view, it works good, but together they don't work.


Solution

  • Both selects have name color ? Shouldn't it be car and client?