我尝试设置规则来验证laravel表单的发布请求以存储数据,但如果我设置任何验证规则(通过或失败),它将只显示空白的空白页面。 我使用laravel 5 表单(视图):
@if (count($errors) > 0)
<div class="alert alert-danger">
<ul>
@foreach ($errors->all() as $error)
<li>{{ $error }}</li>
@endforeach
</ul>
</div>
@endif
{!! Form::open(['action' => 'RentalAgreementController@store', 'method' => 'post']) !!}
{!! Form::label('dateOfAgreement', 'Date of Agreement', ['class' => 'control-label']) !!}
{!! Form::input('date', 'dateOfAgreement' , date('Y-m-d') , ['class' => 'form-control']) !!}
{!! Form::submit('Submit', ['class' => 'button']) !!}
{!! Form::close() !!}
控制器
public function store(StoreAgreementPostRequest $request)
{
$agreement= new RentalAgreement(array(
'dateOfAgreement' => $request->dateOfAgreement,
));
$agreement->save();
Session::flash('flash_message', 'Agreement successfully added! ');
return view('home');
}
StoreAgreementPostRequest
class StoreAgreementPostRequest extends Request {
public function authorize()
{
return true;
}
public function rules()
{
return [
'premiseUse'=>'required|max:5'
];
}
}
只显示黑页,但如果我删除它的工作规则。但对于此应用程序验证方式中的所有其他形式,(所有其他表单和控制器完美地工作)。