我的Web应用程序生成一定数量的表单以在用户输入上注册用户。即如果用户输入2,页面生成两个表单或用户输入的任何数字。我将表单提交给控制器因为我创建了几个用户,所以提交按钮。但是当我点击提交按钮时,la lavel抛出错误“Method Applicant :: __ toString()不得抛出异常”。
无法弄清楚到底在做什么。下面是代码。
create.blade.php
@for($i=1; $i < $num + 1; $i++)
<form method="POST" action="{{URL::route('quickform.store')}}" class="user form-horizontal" enctype="multipart/form-data">
<input type="hidden" name="formnumber" value="{{$num}}">
<!--surname and othernames-->
<div class="form-group">
<div class="col-sm-1 col-md-offset-">
<label for="name">Surname</label>
</div>
<div class="col-sm-3">
<input type="text" name="{{'surname'.$num}}" required value="{{Input::old('surname')}}" class="form-control">
</div>
<div class="col-sm-1 col-md-offset-">
<label for="name">Other Names</label>
</div>
<div class="col-sm-3">
<input type="text" name="{{'othernames'.$num}}" required value="{{Input::old('othernames')}}" class="form-control">
</div>
<div class="col-sm-1 col-md-offset-">
<label for="occupation">Occupation</label>
</div>
<div class="col-sm-3">
<input type="text" name="{{'occupation'.$num}}" required value="{{Input::old('occupation')}}" class="form-control">
</div>
</div>
<!--address and LGA-->
<div class="form-group">
<div class="col-sm-1 col-md-offset-">
<label for="address">Address</label>
</div>
<div class="col-sm-3">
<input type="text" name="{{'address'.$num}}" required value="{{Input::old('address')}}" class="form-control">
</div>
<div class="col-sm-1 col-md-offset-">
<label for="dob">DOB</label>
</div>
<div class="col-sm-3">
<input type="date" name="{{'dob'.$num}}" value="{{Input::old('dob')}}" required class="form-control" class="form-control">
</div>
<div class="col-sm-1 col-md-offset-">
<label for="phone">Phone</label>
</div>
<div class="col-sm-3">
<input type="text" name="{{'phone'.$num}}" required value="{{Input::old('phone')}}" class="form-control">
</div>
</div>
<!--sex DOB GENOTYPE BLOOD GROUP-->
<div class="form-group">
<div class="col-sm-1 col-md-offset-">
<label for="sex">Sex</label>
</div>
<div class="col-sm-1">
<label for="sex">M </label><input type="radio" name="{{'sex'.$num}}" value="M">
<label for="sex">F </label><input type="radio" name="{{'sex'.$num}}" value="F">
</div>
<div class="col-sm-1 col-md-offset-">
<label for="reg_frm">Collector</label>
</div>
<div class="col-sm-2">
<select name="{{'collector'.$num}}" required>
<option value="">CHOOSE--COLLECTOR</option>
@foreach($collectors as $collector)
<option value="{{strtoupper($collector->name)}}">{{$collector->name}}</option>
@endforeach
</select>
</div>
<div class="col-sm-1 col-md-offset-1">
<label for="reg_frm">Validity From:</label>
</div>
<div class="col-sm-2">
<input type="date" name="{{'reg_frm'.$num}}" value="{{Input::old('reg_frm')}}" class="form-control" required>
</div>
<div class="col-sm-1 col-md-offset-">
<label for="reg_to">To</label>
</div>
<div class="col-sm-2">
<input type="date" name="{{'reg_to'.$num}}" value="{{Input::old('reg_no')}}" class="form-control" required>
</div>
</div>
<div class="form-group">
<div class="col-sm-1">
<label for="form_no">Form NO.</label>
</div>
<div class="col-sm-1">
<input type="text" name="{{'form_no'.$num}}" value="{{Input::old('form_no')}}" class="form-control" required>
</div>
<div class="col-sm-1 col-md-offset-">
<label for="tell_no">Reciept NO.</label>
</div>
<div class="col-sm-1">
<input type="text" name="{{'tell_no'.$num}}" value="{{Input::old('tell_no')}}" class="form-control" required>
</div>
<div class="col-sm-1">
<label for="amt_paid">Amount Paid</label>
</div>
<div class="col-sm-1">
<input type="text" name="{{'amt_paid'.$num}}" value="{{Input::old('amt_paid')}}" class="form-control" required>
</div>
<div class="col-sm-1">
<label for="LGA">LGA</label>
</div>
<div class="col-sm-2">
<select onchange="quickfacility('{{URL::to('/quickfacility')}}','{{'facility'.$i}}','{{'lga'.$i}}')" id="{{'lga'.$i}}" name="lga" class="form-control" data-toggle="tooltip" data-placement="top" title="">
<option value="">Choose-LGA</option>
@foreach($LGA as $key => $F_LGA)
<option id="{{'fac'.$key}}" data-lg="{{$F_LGA->id}}" value="{{$F_LGA->LGA_Name}}">{{$F_LGA->LGA_Name}}</option>
@endforeach
</select>
</div>
<div id="{{'facility'.$i}}">
</div>
</div>
<hr style="color:black;height:2px;border:black 1px solid">
<br>
@endfor
formController.php
public function store()
{
$num = Input::get('formnumber');
for($i = 1; $i < $num + 1; $i++)
{
$applicant.$i=new Applicant;
$applicant->surname = strtoupper(Input::get('surname'.$num));
$applicant->othernames = strtoupper(Input::get('othernames'.$num));
$applicant->address = strtoupper(Input::get('address'.$num));
$applicant->lga = strtoupper(Input::get('lga'.$num));
$applicant->sex = strtoupper(Input::get('sex'.$num));
$applicant->dob = strtoupper(Input::get('dob'.$num));
$applicant->genotype = strtoupper(Input::get('genotype'.$num));
$applicant->blood_grp = strtoupper(Input::get('blood_grp'.$num));
$applicant->phone = strtoupper(Input::get('phone'.$num));
$applicant->email = strtoupper(Input::get('email'.$num));
$applicant->occupation = strtoupper(Input::get('occupation'.$num));
$applicant->place_emp = strtoupper(Input::get('place_emp'.$num));
$applicant->facility = strtoupper(Input::get('facility'.$num));
$applicant->medical_his = strtoupper(Input::get('medical_his'.$num));
$applicant->allergy = strtoupper(Input::get('allergy'.$num));
$applicant->reg_frm = strtoupper(Input::get('reg_frm'.$num));
$applicant->reg_to = strtoupper(Input::get('reg_to'.$num));
$applicant->collector = strtoupper(Input::get('collector'.$num));
$applicant->form_no = strtoupper(Input::get('form_no'.$num));
$applicant->tell_no = strtoupper(Input::get('tell_no'.$num));
$applicant->amt_paid = strtoupper(Input::get('amt_paid'.$num));
}
for($i = 1; $i < $num + 1; $i++)
{
$applicant=$applicant.$i;
$applicant->save();
}
return Redirect::to('/')->with('success','Applications successfully created');
}
提前致谢 我无意验证数据