JuD3's avatar
Level 1

Page error after performing search Laravel 5.4.8

Hi Community I just started learning laravel about a month ago and have run into a problem. I am trying to perform a search using formdata. First problem is the data passed is empty and I don't know why. Secondly when I perform the search it gives an error that it can't find the "vehicles" variable. also in chrome it gives an internal error.

public function searchVehicle(SearchVehicleRequest $request){
        $make=$request->input('make');
        $model=$request->input('model');
        $results = Vehicles::where('make', 'LIKE', '%'.$make. '%')->orWhere('model','LIKE', '%'.$model.'%')->paginate(2);
      return view('Garages.home', compact(array('all' => $results)));
 }
  {{ Form::open(['route' => 'search','method' => 'GET']) }}
            <div>
                <div class="wrapper-dropdown-5" tabindex="1" >
                    <span class="placeholder">Select make</span>
                    <ul class="dropdown" style="z-index:1000" name="make" id="vehicle_make">
                        @foreach($vehicles as $vehicle)
                            {{--{{$vehicle->id}}--}}
                            <li class="option-make" id="make" value="{{$vehicle->make}}"><a>{{$vehicle->make}}</a></li>
                            @endforeach
                    </ul>
                </div>
                <div id="dd" class="wrapper-dropdown-5 inactive" tabindex="2"  >
                    <span class="placeholder">Select model</span>
                    <ul class="dropdown" id="vehicle_model" name="model">
                    </ul>
                </div>
            </div>
        <div class="button-wrap">
            {{Form::submit('Search', ['class' => 'submit-button'])}}
        </div>
        {{ Form::close() }}

I also tried a bit of Javascript but updating the pagination was also giving me a problem as I dont know the next step to take to update the pagination:

function searchVehicle(){
    var make = document.getElementById("vehicle_make");
    var strMake = make.options[make.selectedIndex].text;
    var model = document.getElementById("vehicle_model");
    var strModel = model.options[model.selectedIndex].text;
  
    var strUrl = vehicle_url + strMake + '/' +strModel;
    var obj = sendRequest(strUrl);
    while (cardDeck.firstChild) {
        cardDeck.removeChild(cardDeck.firstChild);
    }

}
0 likes
0 replies

Please or to participate in this conversation.