1

Script code:

 <script type="text/javascript">
  function getValue(){
    var getvalue=document.getElementById('brand').value;
    window.location='products' +getvalue;
  }
</script>

This is my script code. Here I am trying to pass the value of the variable 'getvalue'to the route.

Route:

Route::get('products/{getvalue}','categoryController@bValue');

This is my route. Here I am trying to pass the getvalue to the controller.

Controller code:

  public function bValue(Request $getvalue)
{

    echo $getvalue;
}
1
  • doesn't work that way, when the route is called 'products/food' food would be your getValue. Commented Jul 29, 2017 at 6:20

1 Answer 1

1

Try this may it will work..

 // Javascript
    <script type="text/javascript">
      function getValue(){
        var getvalue=document.getElementById('brand').value;
        window.location='products/' +getvalue;
      }
    </script>

// Php
    public function bValue($getvalue)
    {
        echo $getvalue;
    }
Sign up to request clarification or add additional context in comments.

3 Comments

How to give the route
same which is you mentioned in question. You getting any error..?
See updated answer.....you can refer this. You will have a idea.. laravel.com/docs/5.4/controllers#defining-controllers

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.