D
D
DenKG2016-12-17 11:04:12
Laravel
DenKG, 2016-12-17 11:04:12

How to display the data in the table corresponding to the selected field in the dropdown list?

I need to display the weather data for the city that was selected in the drop-down list in the table:

<select>
  @foreach ($testimonies as $testimony)
  <option>{{$testimony->town}}</option>
  @endforeach
</select>

But how to register it in the controller?
The controller itself is:
public function index(Request $request){
    $testimony = new Testimony;
    $testimony->temp = $request->temp;
    $testimony->humidity = $request->humidity;
    $testimony->wind_speed = $request->wind_speed;
    $testimony->direction = $request->direction;
    $testimony->date = $request->date;
    $testimony->time = $request->time;
    $testimony->pressure = $request->pressure;
    $testimony->town = $request->town;
    $testimony->country = $request->country;
    $testimony->sunrise = $request->sunrise;
    $testimony->sunset = $request->sunset;

    $testimony = Testimony::orderBy('id', 'desc')
                  ->get();
            return view('welcome', [
            'testimonies' => $testimony
            ]);
   }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladislav Nagorny, 2016-12-28
@esvils

<select name="city">
  @foreach ($testimonies as $testimony)
  <option>{{$testimony->town}}</option>
  @endforeach
</select>

public function index(Request $request){
    $city = $request->get('city');
    $testimony = Testimony::where('city','LIKE',$city)->orderBy('id', 'desc')
                  ->get();
            return view('welcome', [
            'testimonies' => $testimony
            ]);
   }

If you understand the question

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question