使用获取值搜索过滤器laravel问题

My Controller:

public function FilteredAdsShow(){

    $id= Input::get('category'); //get id from select name="categories"
    $tit = Input::get('titleFilter'); // get title from input text
    $categories = Category::all();

    $ads = Ad::where('category_id','=',$id)
        ->where('active','=',1)
        ->where('title','=',$tit)
        ->orderby('promoted','1')
        ->orderby('created_at','desc')
        ->with('images')
        ->get();

    return view('filtered')
        ->with(compact('ads'))
        ->with(compact('categories'));

}

I have a button on my view that calls a route when it is clicked. I am doing a foreach too to get all values that has that title and where category_id = $id but it's not working.

View:

@extends('layouts.app')

@section('search')
    @include('pieces.search')
@endsection

    @foreach($ads as $ad)
        <div class="col-3 adSection">
            <img src="{{$ad->images->first()->path}}" alt="Imagem do anuncio" class="adImages"/>
            <p>{{$ad->title}}</p>
            <p>{{$ad->price}}</p>
        </div>
    @endforeach

My search components are on my search view i'm including.

View I call my search view:

@section('search') @include('pieces.search') @endsection

@foreach($ads as $ad)
    <div class="col-3 adSection">
        <img src="{{$ad->images->first()->path}}" alt="Imagem do anuncio" class="adImages"/>
        <p>{{$ad->title}}</p>
        <p>{{$ad->price}}</p>
    </div>
@endforeach

And my route:

Route::get('/filteredAds','MainController@FilteredAdsShow')->name('filteredAds');

My search view:

<div class="col-6">
    <div class="form-group">
        <input type="text" name="titleFilter" placeholder="Pesquise pelo título" class="form-control">
    </div>
</div>
<div class="col-4">
    <div class="form-group">
        <select class="form-control" name="category">
            <option value="-1">Todos</option>
            @foreach($categories as $category )
                <option value="{{$category->id}}">{{$category->name}}</option>
            @endforeach
        </select>
    </div>

</div>
<div class="col-2">
    <div class="form-group">
        <a href="{{route('filteredAds')}}" class="btn btn-primary form-control">Pesquisar</a>
    </div>
</div>

Problem is in your anchor tag. your anchor tag is just calling a route but it is not sending any value to controller

To send selected option value to controller you will have to use jquery.

  1. get title value

HTML:

Input tag having some id

    <input type="text" id="titleFilter" name="titleFilter" placeholder="Pesquise pelo título" class="form-control">

Jquery

    var titleFilter = $('#titleFilter').val();

2. get selected value

suppose your select has id categories

<select class="form-control" name="category" id='categories'> ...</select>

$('#categories').on('change',function(){
   //get selected category
   var selectedOption = $('#categories:selected').val()  
   //trigger click here to your route
});

3.trigger click on button when you change dropdown or however you want