lundi 11 mai 2020

How to convert and display the value from the database in laravel

I want do display outlet name as "Food" if the value in the database is "FC" and display "Express" if the value in the database is "EX" in my for each drop down.

Here's my controller

$outlet_name = StoreFC::select('loc_type')
      ->groupBy('loc_type')
      ->orderBy('loc_type', 'ASC')
      ->get();

$district_name = StoreFC::select('location')
    ->groupBy('location')
      ->orderBy('location', 'ASC')
      ->get();
 return view('test.store-fc', compact('outlet_name','district_name'));

Here's my view

<div class="form-group">
  <select name="filter_district" id="filter_district" class="form-control" required>
     <option value="">Select Location</option>
       @foreach ($district_name as $district)
          <option value=""></option>
       @endforeach
  </select>
</div>

<div class="form-group">
  <select name="filter_outlet" id="filter_outlet" class="form-control" required>
     <option value="">Select Outlet</option>
        @foreach($outlet_name as $outlet)
           <option value=""></option>
        @endforeach
  </select>
</div>

Here's my model

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

    class StoreFC extends Model
    {
        protected $table = 'store_foodcity';
    }

This is how it show now in the drop down

This is how it show now in the drop down



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire