make a search form and show result on the same page

Posted 3 months ago by farshadf

i want to make a search form that searches some dates and show the result to user on the same page that search submits which is this case is the show method of laravel which makes the job double hard i think so considering that i am on show method here is some part of my code

     public function show(Property $property)
    {

        $property = Property::with('propertycalendars')->where('id', $property->id)->first();
        foreach ($property->propertycalendars as $prop) {
            $end_reserve = $prop->reserve_end;
        }
//             HERE NEW RELATION
        $pdate = Property::with('dates')->get();

        return view('users.properties.show', compact('property','pdate','end_reserve'));
    }
//    search dates
     public function search (Request $request,Property $property){
    //Send an empty variable to the view, unless the if logic below changes, then it'll send a proper variable to the view.
    $results = null;

    //Runs only if the search has something in it.
    if (!empty($request->property_id)) {
        $start_date = $request->start_date;
        $search_date = Date::all()->where('date',$start_date);
    }
    $pdate = Property::with('dates')->get();
    return view('users.properties.show',compact('search_date','property','pdate'));
}

and here is my route :


Route::resource('/properties','PropertyController');
Route::post('/properties/search','[email protected]');

and finally the form that i use :


 <form action="/properties/search" method="post">
                {{csrf_field()}}

                <div class="row">
                <div class="col-lg-5">
                    <input type="hidden" value="{{$property->id}}" name="property_id">
                    <input name="start_date"  class="form-control m-input start_date" autocomplete="off"></div>

                <div class="col-lg-5">
                    <input name="title"  class="form-control m-input end_date" autocomplete="off"></div>

                <div class="col-lg-2">
                    <input type="submit" value="search" class="btn btn-primary btn-block" autocomplete="off">
                </div>
            </div>
            </form>

so with this code now i get the blank page with nothing inside but i want to show the old property.show page just + to search result . i would be happy to get any kind help if possible ty :)

Please sign in or create an account to participate in this conversation.