我有一个表单,输入是内部循环。每个输入都使用Laravel validation array method进行验证。目前我提交的名称为name="guest[{{ $cart->_id }}][sleeps]"
和name="guest[{{ $cart->_id }}][comments]"
。验证对每个输入都很好。但数据未提交到控制器页面。提交页面重定向后。我得到了http 302 status
。我附加了chrome控制台结果。当我提交表单时,我们如何将数据提交给控制器?
如果我更改name="sleeps[]"
和name="comments[]"
之类的名称,则会将数据发布到控制器中。任何帮助将不胜感激。
routes.php文件
Route::post('/cart/store', 'CartController@store')->name('cart.store');
Html
<form action="{{ route('cart.store') }}" method="post">
{{ csrf_field() }}
<div class="panel panel-default text-left panel-booking1 panel-default-booking1">
@forelse($carts as $key => $cart)
<div class="col-sm-4 col-sm-4-booking1 form-group {{ $errors->has('guest.*.sleeps') ? ' has-error' : '' }}">
<label>Sleep(s)</label>
<select class="form-control form-control-booking1 jsBookCalSleep" name="guest[{{ $cart->_id }}][sleeps]">
<option value="">Choose Sleep(s)</option>
@for($i = 1; $i <= 30; $i++)
<option value="{{ $i }}" @if($i == $cart->sleeps) selected @endif>{{ $i }}</option>
@endfor
</select>
@if ($errors->has('guest.*.sleeps'))
<span class="help-block"><strong>{{ $errors->first('guest.*.sleeps') }}</strong></span>
@endif
</div>
<div class="col-sm-4 col-sm-4-f-booking1 comment-booking1 col-sm-4-booking1">
<div class="form-group {{ $errors->has($inputComments) ? ' has-error' : '' }}">
<textarea id="comments_{{ $cart->_id }}" name="guest[{{ $cart->_id }}][comments]" class="form-control" rows="3" maxlength="300" placeholder="Comment...">{{ old($inputComments) }}</textarea>
@if ($errors->has($inputComments))
<span class="help-block"><strong>{{ $errors->first($inputComments) }}</strong></span>
@endif
</div>
</div>
@empty
<p>No bookings in your cart</p>
@endforelse
<div>
<div id="btn-ground-2-booking1">
<button type="submit" class="btn btn-default-booking1 btn-default btn-sm btn-details btn-details-booking1"><span class="glyphicon glyphicon-credit-card" style="font-size: 14px;" aria-hidden="true"></span> Payment</button>
</div>
</div>
</form>
CartRequest.php
public function rules()
{
return [
'guest.*.sleeps' => 'required|not_in:0',
'guest.*.comments' => 'max:300',
];
}
CartController.php
public function store(CartRequest $request)
{
dd($request->all());
}
答案 0 :(得分:1)
您可以尝试:
conda install -c anaconda beautiful-soup
希望它会对你有所帮助。
答案 1 :(得分:0)
302是重定向代码。像这样
Route::post('/cart/store', 'CartController@store')->name('cart.store');
Replace the form tag by below line and check it.
<?php echo Form::open(['url' => '/cart/store', 'method' => 'post']); ?>