mindphp เขียน: ↑28/10/2020 1:15 pm
ปัญหานี้เป็นไง บ้าง
1. ทำการกดเลือก listbox สนามบินดอนเมือง ,
2. แล้วกดปุ่มค้นหาไป
3. จะวิ่งไปทำงานที่ action="/searchAirflight/search" ใน Form ของ File showAirflight.blade.php
โค้ด: เลือกทั้งหมด
<form class="" method="get" name="search" action="/searchAirflight/search">
<tr>
<th scope="col">ลำดับ</th>
<th scope="col">
<select name="name" id="name" >
<option value="0" selected="selected">---- เลือกทั้งหมด ----</option>
@foreach($searchflight as $searchflights)
<option value="{{$searchflights->id_airport}}"> {{$searchflights->airport['name']}} </option>
@endforeach
</select>
4. ตรงนี้คือ route ของ action="/searchAirflight/search" , มีการวิ่งไปทำงาน Controller_show_airflight แล้ววิ่งไปที่ Function index
โค้ด: เลือกทั้งหมด
Route::get('/searchAirflight/search', 'Controller_show_airflight@index');
5.ส่วนตรงนี้คือ route ไว้โชว์ข้อมูลในตาราง showAirflight
โค้ด: เลือกทั้งหมด
Route::get('/showAirflight','Controller_show_airflight@index');
6.ตรงนี้คือ Controller_show_airflight , แล้วเข้าไปดู code Function index
โค้ด: เลือกทั้งหมด
public function index(Request $request)
{
$name = $request->name;
$searchflight = Airflight::where('id_airport','=','{$name}')->paginate(2);
$searchflight = Airflight::paginate(6);
return view('showAirflight')
->with('searchflight',$searchflight)
->with('flight',Airflight::paginate(6))
->with('airport',Airport::all())
->with('airline',Airline::all())
;
}
7.ผลลัพธ์ที่ได้
ติดปัญหา ตรง : ค้นหาข้อมูลแล้ว , ไม่เกิดการเปลี่ยนอะไรทั้งสิ้น , หมายถึงค้นหาข้อมูลไม่เจอ หรือ ไม่แสดงผล
- Programming - PHP-1.png (32.38 KiB) Viewed 946 times
สรุปคือ
ต้องการให้วิ่งส่งค่าข้อมูลที่ต้องการค้นหาไปหน้าเดียวกัน