Laravel 5 (URL not showing search parameters)

New to Laravel,

My form looks like this

{!! Form::open(array('action' => array('SearchController@postReviews' ), 'class'=>'form-inline')) !!}
    <div class="form-group">
        <input type="hidden" name="_token" value="{{ csrf_token() }}">

        <div class="input-group">
            <div class="input-group-addon" style="width:110px;">Location</div>
            <input type="text" 
                   class="form-control "  
                   id="mapsearch" name="mapsearch" 
                   placeholder="Enter City,Pin or Address" 
                   style="height:43px; min-width:402px; font-size:1.0em;" required/>
            <div class="input-group-addon">
                {!! Form::select('size', 
                    array('Car' => 'Car', '2-Wheeler' => '2-Wheeler'), 
                    'Car', 
                    ['id'=> 'carmodel', 'class' => 'form-control input-sm', 'style'=>'width:200px;',
                    'required']) 
                !!}
            </div>
            <input type="hidden" class="form-control input-sm" name="input_lat" id="input_lat" required>
            <input type="hidden" class="form-control input-sm" name="input_lng" id="input_lng" required>
        </div>
        <button type="submit" class="btn btn-danger" id="btn_search" style="width:200px;height:42px;">Search</button>
   </div>

 </form>

And my controller looks like

public function postReviews()
{
    $location = Input::get('mapsearch');
    $input_lat = Input::get('input_lat');
    $input_lng = Input::get('input_lng');


    $inputs = ($input_lat  && $input_lng);
    if (!$inputs) {

      $input_lat = 22.5667;
      $input_lng = 88.3667;
    }...

Now everything is working fine. I am able to generate results with no issues.

What is troubling me is when I hit search my URL remains the same.

I.e. Before search URL is http://localhost/reviews After search URL is http://localhost/reviews what should I change so that my url after search button click shows

http://localhost/reviews/(value from mapsearch field)

Answers


When you use a POST request, the Input values are sent over post and aren't appended to the URL (as opposed to a get request where they would be sent to something like localhost/reviews?mapsearch=xxxx&input_lat=xxxxx&input_lng=xxxxx). In order to add that segment to the URL you would have to do one of two things:

1) in the Controller, handle the inputs and then redirect them to a route mapped to /reviews/{mapsearch}

or

2) use a bit of javascript on the page to update the URL to show the mapsearch parameter. In order to update the URL they see without sending them to a new page you'd need to use history.pushState. So in your view you would have

<script>
history.pushState({},"URL Rewrite Example","http://localhost/reviews/{{Input::get('mapsearch')}}")
</script>

This would update their URL to show that parameter. This is not supported by all browsers, notably IE <10


First create a controller action

public function reviewWithUri($uri,$data){
    return view('YOUR_VIEW_FILE')->with(['data'->$data]);
}

Then change your postReview returns to redirect to this action.

public function postReview(){
    ........
    return redirect()->action('ReviewController@reviewWithUri', ['uri' =>$uri,'data'=>$data]);
}

Finally routing

Route::get('review/{uri}', ['uses' => 'ReviewController@reviewWithUri', 'as' => 'review.uri']);

Need Your Help

Angular making input field null on validation failure

javascript angularjs

I am creating a member registration form where he enters his membership card number. The membership card number is a 19 digit number which starts with 6 4's and then followed by 13 digits.Now the u...

SimpleGui inputs into a variable

python codeskulptor

On simplegui I want there to be an input box called login_gui that puts the data from the input into the variable login_variable, not into a defined function.