我是Laravel的新手,我正在尝试从复选框中获取值。
我正在尝试接收创建报告所需的regeneration_id
,但是值始终为null
。
查看:
@foreach ($regenerations as $regeneration)
@if ($regeneration -> invoice_id == NULL)
<tr>
<td>{{ $regeneration -> id }}</td>
<td>
@if ($regeneration -> source == 1) Praca: {{ $regeneration -> source_id }}
@elseif ($regeneration -> source == 2) Sprzedaż: {{ $regeneration -> source_id }}
@else Nieznane
@endif </td>
<td>{{ $regeneration -> product_name }}</td>
<td>
@if ($regeneration -> difficulty == 0) Nie ustalono
@else {{ $regeneration -> difficulty }}
@endif
</td>
<td>{{ $regeneration -> date_expected }}</td>
{{-- showing status of each regeneration --}}
<td>
@if ($regeneration -> status == 0 && $regeneration -> state == 2) <font color="red">Salon nie ocenione</font>
@elseif ($regeneration -> status == 0 && $regeneration -> state == 3) Salon ocenione
@elseif ($regeneration -> status == 1 && $regeneration -> state == 3) Wysłane MC ocenione
@elseif ($regeneration -> status == 2 && $regeneration -> state == 3) Odebrane MC ocenione
@elseif ($regeneration -> status == 3 && $regeneration -> state == 3) Wysłane SP ocenione
@elseif ($regeneration -> status == 4 && $regeneration -> state == 3) Odebrane SP ocenione
@elseif ($regeneration -> status == 4 && $regeneration -> state == 4) Odebrane SP niezregenerowane
@elseif ($regeneration -> status == 4 && $regeneration -> state == 5) Odebrane SP zregenerowane
@elseif ($regeneration -> status == 1 && $regeneration -> state == 4) Wysłane MC niezregenerowane
@elseif ($regeneration -> status == 1 && $regeneration -> state == 5) Wysłane MC zregenerowane
@elseif ($regeneration -> status == 2 && $regeneration -> state == 4) Odebrane MC niezregenerowane
@elseif ($regeneration -> status == 2 && $regeneration -> state == 5) Odebrane MC zregenerowane
@elseif ($regeneration -> status == 0 && $regeneration -> state == 6) Salon wstrzymane
@endif
</td>
<td>{{$regeneration -> wholesale_price}} zł</td>
{{-- checkbox to add regeneration to an invoice --}}
<td>
<a href="{{ url ('actual', $regeneration -> id ) }}">Szczegóły</a>
</td>
<form method="POST" action = "{{ action ('RegenerationsInvoicesController@generate')}}">
{{csrf_field()}}
<td>
<div class="form-check">
<input type="checkbox" name="regeneration[]" value = {{ $regeneration-> id }} ></input>
</div>
</td>
@endif
@endforeach
</tr>
</table>
<button style="float: right;" type="submit" class= "btn btn-outline-success">Rozlicz</button>
</form>
控制器:
public function generate (Request $req)
{
$regeneration_id = Input::get('regeneration');
var_dump($regeneration_id);
}
我正在尝试从复选框获取输入,但始终失败。 那是因为我的表格从@foreach之外开始吗?请帮忙。
路线:
Route::post('/generateinvoice',RegenerationsInvoicesController@generate');
答案 0 :(得分:0)
在这里尝试
public function generate (Request $req)
{
$regeneration_id = $req->input('regeneration');
var_dump($regeneration_id);
}
修改后的更改视图
@foreach ($regenerations as $regeneration)
@if ($regeneration -> invoice_id == NULL)
<tr>
<td>{{ $regeneration -> id }}</td>
<td>
@if ($regeneration -> source == 1) Praca: {{ $regeneration -> source_id }}
@elseif ($regeneration -> source == 2) Sprzedaż: {{ $regeneration -> source_id }}
@else Nieznane
@endif </td>
<td>{{ $regeneration -> product_name }}</td>
<td>
@if ($regeneration -> difficulty == 0) Nie ustalono
@else {{ $regeneration -> difficulty }}
@endif
</td>
<td>{{ $regeneration -> date_expected }}</td>
{{-- showing status of each regeneration --}}
<td>
@if ($regeneration -> status == 0 && $regeneration -> state == 2) <font color="red">Salon nie ocenione</font>
@elseif ($regeneration -> status == 0 && $regeneration -> state == 3) Salon ocenione
@elseif ($regeneration -> status == 1 && $regeneration -> state == 3) Wysłane MC ocenione
@elseif ($regeneration -> status == 2 && $regeneration -> state == 3) Odebrane MC ocenione
@elseif ($regeneration -> status == 3 && $regeneration -> state == 3) Wysłane SP ocenione
@elseif ($regeneration -> status == 4 && $regeneration -> state == 3) Odebrane SP ocenione
@elseif ($regeneration -> status == 4 && $regeneration -> state == 4) Odebrane SP niezregenerowane
@elseif ($regeneration -> status == 4 && $regeneration -> state == 5) Odebrane SP zregenerowane
@elseif ($regeneration -> status == 1 && $regeneration -> state == 4) Wysłane MC niezregenerowane
@elseif ($regeneration -> status == 1 && $regeneration -> state == 5) Wysłane MC zregenerowane
@elseif ($regeneration -> status == 2 && $regeneration -> state == 4) Odebrane MC niezregenerowane
@elseif ($regeneration -> status == 2 && $regeneration -> state == 5) Odebrane MC zregenerowane
@elseif ($regeneration -> status == 0 && $regeneration -> state == 6) Salon wstrzymane
@endif
</td>
<td>{{$regeneration -> wholesale_price}} zł</td>
{{-- checkbox to add regeneration to an invoice --}}
<td>
<a href="{{ url ('actual', $regeneration -> id ) }}">Szczegóły</a>
</td>
@endif
@endforeach
<form method="POST" action = "{{ action ('RegenerationsInvoicesController@generate')}}">
{{csrf_field()}}
@foreach ($regenerations as $regeneration)
@if ($regeneration -> invoice_id == NULL)
<td>
<div class="form-check">
<input type="checkbox" name="regeneration[]" value = {{ $regeneration-> id }} ></input>
</div>
</td>
@endif
@endforeach
</tr>
</table>
<button style="float: right;" type="submit" class= "btn btn-outline-success">Rozlicz</button>
</form>
答案 1 :(得分:0)
谢谢大家为这个挑战付出的努力。我终于找到了问题所在。 问题只在于视图。我将表格放置的太远了,应该放在表格的开头。正确的视图应该看起来像这样,并且效果很好。
<form method="POST" action = "{{ action ('RegenerationsInvoicesController@generate')}}">
{{csrf_field()}}
<table style="width:100%">
<tr>
<th>ID </th>
<th>Źródło</th>
<th>Produkt</th>
<th>Stopień trudności</th>
<th>Spodziewana data</th>
<th>Status</th>
<th>Cena</th>
<th></th>
<th>Rozlicz</th>
</tr>
@foreach ($regenerations as $regeneration)
@if ($regeneration -> invoice_id == NULL)
<tr>
<td>{{ $regeneration -> id }}</td>
<td>
@if ($regeneration -> source == 1) Praca: {{ $regeneration -> source_id }}
@elseif ($regeneration -> source == 2) Sprzedaż: {{ $regeneration -> source_id }}
@else Nieznane
@endif </td>
<td>{{ $regeneration -> product_name }}</td>
<td>
@if ($regeneration -> difficulty == 0) Nie ustalono
@else {{ $regeneration -> difficulty }}
@endif
</td>
<td>{{ $regeneration -> date_expected }}</td>
{{-- Wyświetlanie statusu złożonego z state i status --}}
<td>
@if ($regeneration -> status == 0 && $regeneration -> state == 2) <font color="red">Salon nie ocenione</font>
@elseif ($regeneration -> status == 0 && $regeneration -> state == 3) Salon ocenione
@elseif ($regeneration -> status == 1 && $regeneration -> state == 3) Wysłane MC ocenione
@elseif ($regeneration -> status == 2 && $regeneration -> state == 3) Odebrane MC ocenione
@elseif ($regeneration -> status == 3 && $regeneration -> state == 3) Wysłane SP ocenione
@elseif ($regeneration -> status == 4 && $regeneration -> state == 3) Odebrane SP ocenione
@elseif ($regeneration -> status == 4 && $regeneration -> state == 4) Odebrane SP niezregenerowane
@elseif ($regeneration -> status == 4 && $regeneration -> state == 5) Odebrane SP zregenerowane
@elseif ($regeneration -> status == 1 && $regeneration -> state == 4) Wysłane MC niezregenerowane
@elseif ($regeneration -> status == 1 && $regeneration -> state == 5) Wysłane MC zregenerowane
@elseif ($regeneration -> status == 2 && $regeneration -> state == 4) Odebrane MC niezregenerowane
@elseif ($regeneration -> status == 2 && $regeneration -> state == 5) Odebrane MC zregenerowane
@elseif ($regeneration -> status == 0 && $regeneration -> state == 6) Salon wstrzymane
@endif
</td>
<td>{{$regeneration -> wholesale_price}} zł</td>
{{-- checkbox do dodania do rozliczenia --}}
<td>
<a href="{{ url ('actual', $regeneration -> id ) }}">Szczegóły</a>
</td>
<td>
<div class="form-check">
<input type="checkbox" name="regeneration[]" value = "{{ $regeneration -> id }}" ></input>
</div>
</td>
@endif
@endforeach
</tr>
</table>
<button style="float: right;" type="submit" class= "btn btn-outline-success">Rozlicz</button>
</form>