【发布时间】:2015-04-30 08:57:02
【问题描述】:
所以我是 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>
感谢任何帮助!
【问题讨论】:
-
这看起来问题可能出在视图中。请通过编辑您的问题发布该代码。并且不要将其作为图像发布,而只是(正确格式化)文本。这样可以保证它在许多设备上的可搜索性和可读性。
-
按照您的要求编辑了帖子
-
invoice_number是否可能是一个数组而不仅仅是一个数字?在控制器中尝试dd($invoice_number)。 -
您似乎没有在
store()方法中实际设置invoice_number,但您在create()方法中设置了这可能是它在那里工作的原因。 -
@JoelHinz,我不太明白...有一个重定向要创建,所以创建控制器被再次调用?