How to pass two variables from a view to the controller?

Asked

Viewed 512 times

3

i have a link where I already pass a variable to the controller. It works ok. How do I pass two?

My link in View:

<a href="{{url("/ordemvar/$equipam->codigoequipamento")}}"><i class="glyphicon glyphicon-tasks"></i></a>

It would be something like that?

<a href="{{url("/ordemvar/$equipam->id?$equipam->codigoequipamento")}}"><i class="glyphicon glyphicon-tasks"></i></a>

How I pick up the controller

public function pegaEquipa($prm)
{
return $prm;
}

Thanks

  • Have you researched Ajax?

  • No. This method works well. Just not how to pass more than one.

  • Pass the values you want as a list, for example: [123,321,145], so in Backend you will only need to capture this list with the explode function.

1 answer

2


You can do it in many ways.

<a href="{ {url("/ordemvar/$equipam->codigoequipamento/$equipam->nome") }}"> Link </a>

See that above has two slugs bar separated.

So your controller would look like this:

public function pegaEquipa($slug1, $slug2)
{
    echo $slug1;
    echo '<br>';
    echo $slug2;
}

Or by Querystring.

<a href="{ {url("/ordemvar?id=$equipam->codigoequipamento&nome=$equipam->nome") }}"> Link </a>

And the controller would look like this:

public function pegaEquipa(Request $request)
{
    echo $request->get('id');
    echo '<br>';
    echo $request->get('nome');
}
  • 2

    to use with 2 parameters do not forget to add the same on the route ::get('name/{P1}/{P2})`

  • It worked perfectly. Thank you.

  • @Rafaelacioly is. I was hoping he’d say that later. Rsrs

Browser other questions tagged

You are not signed in. Login or sign up in order to post.