所以我是laravel 5的新手,刚开始编写我自己的应用程序.
当我只调用invoices.create控制器的路由时,视图生成就好了.
当我从invoices.store控制器重定向到同一视图时,我收到以下错误消息.
我的控制器,看起来像这样.
我猜它与传递给控制器的参数相矛盾,看着消息.但我似乎无法找到什么错误以及如何解决它.
编辑:
这是观点……
@extends('app')
@section('content')
<div class="row">
<div class="col-md-10 col-md-offset-1">
<div class="panel panel-default">
<div class="panel-heading">New Invoice</div>
<div class="panel-body">
@if ($errors->has())
<div class="alert alert-danger">
@foreach ($errors->all() as $error)
{{ $error }}<br>
@endforeach
</div>
@endif
{!! Form::model(new App\Invoice, array('route' => array('invoices.store'))) !!}
<div class="form-group">
{!! Form::label('customer_id', 'Choose customer:') !!}
{!! Form::select('customer_id', array(null => ' - Please select customer - ') + $customers, $selected_customer, array('class'=>'form-control')) !!}
</div>
<div class="row" id="company_row">
<div class="col col-sm-6">
<div class="form-group">
{!! Form::label('number', 'Number:') !!}
{!! Form::text('number', $invoice_number, array('class'=>'form-control')) !!}
</div>
</div>
<div class="col col-sm-6">
<div class="form-group">
{!! Form::label('date', 'Date:') !!}
{!! Form::text('date', null, array('class'=>'form-control')) !!}
</div>
</div>
</div>
<div class="panel panel-default">
<div class="panel-heading">Invoice items</div>
<div class="panel-body">
<div class="table-responsive">
<table class="table table-bordered" id="table-invoice-items">
<thead>
<tr>
<th>Amount</th>
<th>Description</th>
<th>Price</th>
<th>Total</th>
<th>VAT</th>
</tr>
</thead>
<tbody>
<tr>
<td class="cell-width-5">{!! Form::text('items[amount][]', null, array('class'=>'form-control')) !!}</td>
<td>{!! Form::text('items[description][]', null, array('class'=>'form-control')) !!}</td>
<td class="cell-width-6">{!! Form::text('items[price][]', null, array('class'=>'form-control')) !!}</td>
<td class="cell-width-5"></td>
<td class="cell-width-12">{!! Form::text('items[vat][]', null, array('class'=>'form-control')) !!}</td>
<td class="cell-center"><span class="glyphicon glyphicon-trash pointer" aria-hidden="true"></span></td>
</tr>
</tbody>
</table>
</div>
<button type="button" class="btn btn-primary" id="add-invoice-item">New Item</button>
</div>
</div>
<div class="form-group">
{!! Form::label('note', 'Note:') !!}
{!! Form::textarea('note', null, array('class'=>'form-control')) !!}
</div>
<div class="form-group">
{!! Form::submit('Create Invoice', ['class'=>'btn primary']) !!}
</div>
{!! Form::close() !!}
</div>
</div>
</div>
</div>
<script>
$(document).ready(function(){
$("input#date").datepicker({format: 'dd-mm-yyyy'});
$("button#add-invoice-item").click(function(){
var table_row = $("table#table-invoice-items > tbody > tr:first").clone();
table_row.find('input:text').val('');
$("table#table-invoice-items > tbody > tr:last").after(table_row);
});
});
</script>
@endsection
好的,所以我设法缩小了问题.它与数组有关,作为输入字段的名称,当我删除此表行时…错误消失了.
但是我该如何解决这个问题呢?
<tr>
<td class="cell-width-5">{!! Form::text('items[amount][]', null, array('class'=>'form-control')) !!}</td>
<td>{!! Form::text('items[description][]', null, array('class'=>'form-control')) !!}</td>
<td class="cell-width-6">{!! Form::text('items[price][]', null, array('class'=>'form-control')) !!}</td>
<td class="cell-width-5"></td>
<td class="cell-width-12">{!! Form::text('items[vat][]', null, array('class'=>'form-control')) !!}</td>
<td class="cell-center"><span class="glyphicon glyphicon-trash pointer" aria-hidden="true"></span></td>
</tr>
任何帮助表示赞赏!
解决方法:
编辑:这是Laravel的表单构建器的已知问题:https://github.com/laravel/framework/issues/2243
它会阻止您使用数组作为Form :: text()方法调用的name参数.我认为它与表单如何从HTML中的给定模型分配值有关.
我认为你将不得不为该部分编写基本的HTML表单.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。