Answer the question
In order to leave comments, you need to log in
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>
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
<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
]);
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question