Php Laravel validation ErrorException-htmlentities()要求参数1为字符串,数组给定
所以我对Laravel5是新手,刚刚开始编写自己的应用程序 当我刚刚调用invoices.create控制器的路由时,视图生成的结果很好 当我从invoices.store控制器重定向到同一个视图时,我收到以下错误消息 我的控制器,看起来像这样 我猜它与传递给控制器的参数冲突,查看消息。但我似乎找不到问题所在,也找不到解决方法 编辑: 这是我的看法Php Laravel validation ErrorException-htmlentities()要求参数1为字符串,数组给定,php,laravel-5,Php,Laravel 5,所以我对Laravel5是新手,刚刚开始编写自己的应用程序 当我刚刚调用invoices.create控制器的路由时,视图生成的结果很好 当我从invoices.store控制器重定向到同一个视图时,我收到以下错误消息 我的控制器,看起来像这样 我猜它与传递给控制器的参数冲突,查看消息。但我似乎找不到问题所在,也找不到解决方法 编辑: 这是我的看法 @extends('app') @section('content') <div class="row"> <di
@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
@extends('app')
@节(“内容”)
新发票
@如果($errors->has())
@foreach($errors->all()作为$error)
{{$error}}
@endforeach
@恩迪夫
{!!Form::model(新应用\发票,数组('route'=>array('invoices.store'))
{!!Form::label('customer_id','Choose customer:')
{!!Form::select('customer_id',array(null=>')-请选择customer-')+$customers,$selected_customer,array('class'=>'Form-control'))
{!!Form::label('number','number:')
{!!Form::text('number',$invoice_number,数组('class'=>'Form-control'))
{!!Form::label('date','date:')
{!!Form::text('date',null,array('class'=>'Form-control'))
发票项目
数量
描述
价格
全部的
增值税
{!!Form::text('items[amount][],null,array('class'=>'Form-control'))
{!!Form::text('items[description][],null,array('class'=>'Form-control'))
{!!Form::text('items[price][],null,array('class'=>'Form-control'))
{!!Form::text('items[vat][],null,array('class'=>'Form-control'))
新项目
{!!Form::label('note','note:')
{!!Form::textarea('note',null,array('class'=>'Form-control'))
{!!表单::提交('Create Invoice',['class'=>'btn primary'])
{!!Form::close()!!}
$(文档).ready(函数(){
$(“输入#日期”).datepicker({格式:'dd-mm-yyyy'});
$(“添加发票项按钮”)。单击(函数(){
var table_row=$(“table#table invoice items>tbody>tr:first”).clone();
表_row.find('input:text').val('');
$(“表#表发票项目>tbody>tr:last”)。之后(表#行);
});
});
@端部
好吧,所以我设法缩小了问题的范围。当我删除此表行时,它与作为输入字段名称的数组有关。。错误消失了。
但我该如何解决这个问题呢
<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>
{!!Form::text('items[amount][],null,array('class'=>'Form-control'))
{!!Form::text('items[description][],null,array('class'=>'Form-control'))
{!!Form::text('items[price][],null,array('class'=>'Form-control'))
{!!Form::text('items[vat][],null,array('class'=>'Form-control'))
感谢您的帮助 编辑:这是Laravel表单生成器的已知问题: 它阻止您将数组用作Form::text()方法调用的名称参数。我认为这与表单如何从HTML中给定的模型赋值有关
我认为您必须为该部分编写基本的HTML表单 嗯,我设法重现了这个问题。我有一个文件数组字段:
<input type="file" name="files[]" />
我还试图得到像这样的旧值字段:
<input type="file" name="files[]" value="{{ old('files') }}" />
正如我发现的那样,由于某种原因,这导致了htmlentities()的错误。如果有人有时间检查这个案例,请写下你的结果 不要在表单字段名称中使用
[]
,而是指定一个整数[1]
并递增
例如,这:
{!! Form::text('items[amount][]', null, array('class'=>'form-control')) !!}
将是:
{!! Form::text('items[amount][1]', null, array('class'=>'form-control')) !!}
进一步阅读:
看起来问题可能在视图中。请通过编辑您的问题发布代码。不要将其作为图像发布,而只是(正确格式化)文本。通过这种方式,它可以在许多设备上进行搜索和可读性得到保证。当您询问时编辑帖子是否
invoice\u number
可能是一个数组而不仅仅是一个数字?在控制器中尝试dd($invoice\u number)
。您似乎没有实际设置