我的问题是,如果我填写表单字段中的所有数据并发送或不显示错误消息以及数据不会进入其数据库。
这是控制器功能即时通讯。
public function store(Request $request)
{
$this->validate($request, [
'trainee_id' => 'required',
'Trainee_Name' => 'required',
'bank_name' => 'required',
'branch_name' => 'required',
'account_no' => 'required',
]);
bankdetails::create($request->all());
Session::flash('success', 'New Record has been added!');
return view('bankdetails.bankdetailssucess');
}
这是对此的看法。
<div class="col-md-12">
<div class="row">
<div class="col-md-8 col-md-offset-2">
<div class="panel panel-default">
<div class="panel-heading">
<h2>Fill Your Bank Details</h2>
</div>
<div class="panel-body">
<form action="{{route('bankdetails.store')}}" method="post" >
{{ csrf_field() }}
@if ($errors->any())
<div class="alert alert-danger">
<ul>
@foreach ($errors->all() as $error)
<li>{{ $error }}</li>
@endforeach
</ul>
</div>
@endif
<div class="form-group{{ $errors->has('trainee_id') ? ' has-error' : '' }}">
<label>Trainee ID</label>
<input type="text" name="trainee_id" class="form-control" value="MOB/TR/">
</div>
<div class="form-group{{ $errors->has('trainee_name') ? ' has-error' : '' }}">
<label>Trainee Name</label>
<input type="text" name="trainee_name" class="form-control" value="">
</div>
<div class="form-group{{ $errors->has('bank_acc_name') ? ' has-error' : '' }}">
<label>Bank Name</label>
<input type="text" name="bank_acc_name" class="form-control" value="">
</div>
<div class="form-group{{ $errors->has('branch_acc_name') ? ' has-error' : '' }}">
<label>Branch Name</label>
<input type="text" name="branch_acc_name" class="form-control" value="">
</div>
<div class="form-group{{ $errors->has('accoun_no') ? ' has-error' : '' }}">
<label>Account No</label>
<input type="text" name="accoun_no" class="form-control" value="">
</div>
<input type="submit" class="btn btn-success pull-right">
</form>
</div>
</div>
</div>
</div>
</div>
任何人都可以说我为什么会遇到这个问题。
答案 0 :(得分:1)
视图中的name
属性应与控制器上的规则匹配。
$this->validate($request, [
'trainee_id' => 'required',
'Trainee_Name' => 'required', // is Case sensitive?
'bank_name' => 'required', // bank_name exist in your form?
'branch_name' => 'required', // branch_name exist in your form?
'accoun_no' => 'required', // In HTML you wrote account_no and here is accoun_no
]);