ตัวอย่าง Code จาก File showAirflight.blade.php
โค้ด: เลือกทั้งหมด
<form class="" method="get" action="/searchAirflight/search">
<tr>
<th scope="col">
<br><br>ลำดับ</br></br></th>
<th scope="col">
<select name="name" id="name">
<option selected="selected">---- เลือกทั้งหมด ----</option>
@foreach($flight as $flights)
<option value="{{$flights->id_airport}}" >{{$flights->airport['name']}}</option>
@endforeach
</select>
<br><br>ชื่อที่ตั้งสนามบิน</br></br></th>
<th scope="col">
<select name="name_airline" id="name_airline">
<option selected="selected">---- เลือกทั้งหมด ----</option>
@foreach($flight as $flights)
<option value="{{$flights->airline['name_airline']}}">{{$flights->airline['name_airline']}}</option>
@endforeach
</select>
<br><br>ชื่อสายการบิน</br></br></th>
<th scope="col">
<select name="path" id="path">
<option selected="selected">---- เลือกทั้งหมด ----</option>
@foreach($flight as $flights)
<option value="{{$flights->path}}" >{{$flights->path}}</option>
@endforeach
</select>
<br><br>เส้นทางการบิน</br></br></th>
<th scope="col">
<select name="date" id="date">
<option selected="selected">---- เลือกทั้งหมด ----</option>
@foreach($flight as $flights)
<option value="{{$flights->date}}" >{{$flights->date}}</option>
@endforeach
</select>
<br><br>วันที่</br></br></th>
<th scope="col">
<select name="timeout" id="timeout">
<option selected="selected">---- เลือกทั้งหมด ----</option>
@foreach($flight as $flights)
<option value="{{$flights->timeout}}" >{{$flights->timeout}}</option>
@endforeach
</select>
<br><br>เวลาออกเดินทาง</br></br></th>
<th scope="col">
<select name="price" id="price">
<option selected="selected">---- เลือกทั้งหมด ----</option>
@foreach($flight as $flights)
<option value="{{$flights->price}}" >{{$flights->price}}</option>
@endforeach
</select>
<br><br>ราคา</br></br></th>
<th scope="col">
<select name="model_aircraft" id="model_aircraft">
<option selected="selected">---- เลือกทั้งหมด ----</option>
@foreach($flight as $flights)
<option value="{{$flights->model_aircraft}}" >{{$flights->model_aircraft}}</option>
@endforeach
</select>
<br><br>รุ่นเครื่องบิน</br></br></th>
<th scope="col">
<button type="submit" name="submit" class="btn btn-primary" name="submit">ค้นหา</button>
<br><br>แก้ไข</br></br></th>
<th scope="col">
<br><br>ลบ</br></br></th>
</tr>
</form>
โค้ด: เลือกทั้งหมด
public function search(Request $request)
{
$name = $request->name; //รับค่าจาก $request มา , ส่วน 'name' มาจาก ....
//... Folders resources/views/showAirflight.blade.php ก็คือ ชื่อที่ตั้งสนามบิน
$flight = Airflight::where('id_airport',"LIKE","%{$name}%")->paginate(2); //Query ข้อมูลแบบมีเงื่อนไข ใช้ Where , ส่วน 'name' ...
//... คือ colums name จาก ตาราง database , ส่วน "LIKE" ...
//... ถ้าเป็น String(ข้อความ) ให้ระบุเป็น Keyword ....
//... ส่วน % ให้ค้น ชื่อที่ตั้งสนามบินทั้งหมด ทั้งข้างหน้า และ ข้างหลัง
return view("showAirflight")
->with('flight',$flight)
->with('airport',Airport::paginate(2))
->with('airline',Airline::paginate(2))
;
}