M
M
miniven2016-03-22 09:17:14
HTML
miniven, 2016-03-22 09:17:14

How to select multiple inputs in laravel to send values ​​to the database?

There are several inputs received via foreach. How do I get the value of each and send each to the db referring to the id using Request?

@foreach ($services as $service)
  <div class="row">
    <div class="col-md-9">
      {{ Form::text('services_item', $service->service_item, array('class' => 'form-control input-services', 'placeholder' => 'Введите название услуги')) }}
    </div>
    <div class="col-md-1">
      <a href="/service_{{ $service->id }}/delete" class="btn btn-danger">Удалить</a>
    </div>
  </div>
@endforeach

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrzej Wielski, 2016-03-22
@miniven

Pass an array as the name attribute. For example:

@foreach ($services as $service)
  <div class="row">
    <div class="col-md-9">
      {{ Form::text("services_item[]", $service->service_item, array('class' => 'form-control input-services', 'placeholder' => 'Введите название услуги')) }}
    </div>
    <div class="col-md-1">
      <a href="/service_{{ $service->id }}/delete" class="btn btn-danger">Удалить</a>
    </div>
  </div>
@endforeach

Get an array of services_item[] values ​​in request
You can also pass something like
In this case, get an associative array

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question