Search functionality in Laravel

While I was working on my most recent project which was a train ticket booking system I had to implement a trip search functionality which has to return result for the selected trip origin,trip destination,trip date and return the result for all available train for that route and that selected date and also return count for the available number of seat(s) left for the each trains. . I thought of it and saw that I will need to make the search field to be able to query the database for three input values which are trip origin,trip destination and trip date. After implementing it successfully I decided that I should write an article on it even if it is quite easy and staright for those who have made use of it,it is very tasking for those who have never made use of it . Below are the code snippet for the search functionality..

The code below is my search function in the controller;

    public function search()
    {
    $search_text = $_GET['query'];
    $search_text1 = $_GET['query1'];
    $search_text2 = $_GET['datee'];
    $searchtrip = Train::where('origin',  'LIKE', '%' . $search_text. '%')->Where('destination',  'LIKE', '%' . $search_text1. '%')->Where('travel_date',  'LIKE', '%' . $search_text2. '%')->get();
    //This seat search counter below  is when all travel route are combined on one train for the choosen date
     $searchseat = Order::where('travel_date',  'LIKE', '%' . $search_text2. '%')->get();
    return view('result',compact ('searchtrip','searchseat'));
    }

This code below if for the search form ;

   <div class="tab-pane fade show active" id="one-way" role="tabpanel" aria-labelledby="one-way-tab">
                                    <div class="contact-form-action">
                                        <form  class="row align-items-center" action="{{route('result')}}" method="GET">
                                            <div class="col-lg-6 pr-0">
                                                <div class="input-box">
                                                    <label class="label-text">Flying from</label>
                                                    <div class="form-group select-contain w-auto">
                                                        <select class="select-contain-select" name="query">
                                                        @if(count($stations) > 0)    
                                    @foreach($stations as $station)  
                                  <option value="{{$station->train_station}}" >{{$station->train_station}}</option>

                                                            @endforeach
                                                            @endif

                                                        </select>
                                                    </div>
                                                </div>
                                            </div><!-- end col-lg-3 -->
                                            <div class="col-lg-6">
                                                <div class="input-box">
                                                    <label class="label-text">Flying to</label>
                                                    <div class="form-group select-contain w-auto">
                                                        <select class="select-contain-select" name="query1">
                                                        @if(count($stations) > 0)    
                                    @foreach($stations as $station)  
                                  <option value="{{$station->train_station}}" >{{$station->train_station}}</option>

                                                            @endforeach
                                                            @endif
                                                        </select>
                                                    </div>
                                                </div>
                                            </div><!-- end col-lg-3 -->

                                            <div class="col-lg-3 pr-0">
                                                <div class="input-box">
                                                    <label class="label-text">Departing On</label>
                                                    <div class="form-group">

                                                     <input class="date-range form-control" type="date" name="datee" value="2021-09-01">
                                                    </div>
                                                </div>
                                            </div>
                 <div class="col-lg-3">
                                                <button class="theme-btn w-100 text-center margin-top-20px">Search My Train</button>
                                            </div>
                                        </form>
                                    </div>
                                </div>

This code below is my route ;

Route::get('/result', 'StationController@search')->name('result');

Below is a screenshot of the Trip search result ;

Web capture_17-9-2021_103525_localhost.jpeg

I hope this article makes the life of a developer easier .