How to pick up the selected data from a checkbox by the checkbox

Asked

Viewed 312 times

-1

Hello, all right?

I have the following form:

  <div class="form-group">
    <label for="stock_options">Opções de Estoque</label>
    @foreach($stockOptions as $stockOption)
    <div class="form-check col-md-3">
      <input class="form-check-input" type="checkbox" name="stockOption" value="{{$stockOption->stock_option_id}}">
      <label class="form-check-label" for="stockOption">{{$stockOption->name}}</label>
      <input type="text" class="form-control" name="stockOptionQuantity" placeholder="Quantidade">
    </div>
    @endforeach
  </div>

This is within a registration of the product where I am trying to register the stock options, it would select the stock options and put how much is necessary of that option to make the product. At the moment I’m not sure how to get only the "Inputs" selected and the amount of them to be caught in the create.

1 answer

0


In the function to which the route of this request is being directed, certainly store, you must take the data of the variable $request, being able to assign the values to another variable:

$inputs = $request->all();

or taking a specific field:

$stockOption = $request->input('stockOption');

To test what is assigned to a variable you can use the dd function():

dd($stockOption);

You can find more information about requests in the Laravel documentation, follow the link: https://laravel.com/docs/7.x/requests

  • Oh, thank you very much, it worked out that way. One thing I learned at work is to put the name of the inputs as "stockAction[]" and when I get the values they are inside an array in the controller, half gambis but funnel

Browser other questions tagged

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