我想用表单添加新的法律详细信息,此表单有两个按钮,如更新和取消。
当我点击取消按钮时,表单被取消并被重定向到上一页,当我点击更新按钮而没有填写表格细节时,它要求验证。
填写表格的所有必要细节后,当我点击更新按钮时,它会抛出错误,如RouteCollection.php第218行中的MethodNotAllowedHttpException:
我的表格是:
{!! Form::open(array('url' => 'admin/companymaster/updateLocation', 'id'=>'updatelocations', 'class' => 'form-horizontal create_form', 'files' => true)) !!}
<input type="hidden" value="{{$value->id}}" name="company_master_id">
<div id="sublaws_content1"></div>
<div id="save" style="display:none; margin-bottom: 20px;">
<button type="submit" class="btn btn-success" id="senddatepicker">Update</button>
<a class="btn red" href="{{ URL::to('admin/companymaster/'.$company_master->id) }}">Cancel</a>
</div>
</form>
我的路线是:
Route::post('admin/companymaster/updatelocations', 'CompanyController@updateLocation');
我的控制器是:
public function updateLocation(){
//dd(Input::all());
/*Insert Company Law Details*/
$companydetails_id = Input::get('company_master_id');
$company_sub_laws = Input::get('company_sub_laws');
if($company_sub_laws!="")
{
$cld=0;
foreach($company_sub_laws as $rescompany_sublaws)
{
if($companydetails_id!="" && $rescompany_sublaws!="")
{
$law_reg_no = $_POST['law_reg_no'];
$sub_law_start_date = $_POST['sub_law_start_date'][$cld];
$sub_law_end_date = $_POST['sub_law_end_date'][$cld];
$companylawdetails = new CompanyLawDetails;
$companylawdetails->company_master_details_id = $companydetails_id;
$companylawdetails->company_sub_law_id = $rescompany_sublaws;
$companylawdetails->law_reg_no = $law_reg_no;
$company_sub_law_start_date = $sub_law_start_date;
$company_sub_law_end_date = $sub_law_end_date;
if($company_sub_law_end_date!="")
{
$res_company_sub_law_end_date=explode("-",$company_sub_law_end_date);
$company_sub_law_end_date=$res_company_sub_law_end_date[2]."-".$res_company_sub_law_end_date[1]."-".$res_company_sub_law_end_date[0];
$companylawdetails->law_end_date = $company_sub_law_end_date;
}
if($company_sub_law_start_date!="")
{
$res_company_sub_law_start_date=explode("-",$company_sub_law_start_date);
$company_sub_law_start_date=$res_company_sub_law_start_date[2]."-".$res_company_sub_law_start_date[1]."-".$res_company_sub_law_start_date[0];
$companylawdetails->law_start_date = $company_sub_law_start_date;
}
$companylawdetails->save();
}
$cld++;
}
}
$sublaws = CompanyLawDetails::where('company_master_details_id',$companydetails_id)->select('company_sub_law_id')->get()->toArray();
$sublaws = join(",",array_column($sublaws,'company_sub_law_id'));
$update = CompanyDetails::where('id',$companydetails_id)->update(['company_sub_laws' => $sublaws]);
//return Redirect::back();
}
任何人都可以帮我解决这个问题。?
答案 0 :(得分:1)
您似乎走错路线,并且网址出错,请尝试这种方式;
Route::post('admin/companymaster/updatelocations', ['uses'=>'CompanyController@updateLocation',
'as'=>'upload.locations']);
on your blade
{!! Form::open(array('route'=> 'upload.locations', 'method'=>'post', 'id'=>'updatelocations', 'class' => 'form-horizontal create_form', 'files' => true)) !!}
<input type="hidden" value="{{$value->id}}" name="company_master_id">
<div id="sublaws_content1"></div>
<div id="save" style="display:none; margin-bottom: 20px;">
<button type="submit" class="btn btn-success" id="senddatepicker">Update</button>
<a class="btn red" href="{{ URL::to('admin/companymaster/'.$company_master->id) }}">Cancel</a>
</div>
</form>
答案 1 :(得分:0)
请将表单方法添加为'method' => 'post',
{!! Form::open(array('url' => 'admin/companymaster/updateLocation', 'id'=>'updatelocations', 'class' => 'form-horizontal create_form', 'files' => true,'method' => 'post')) !!}
希望你明白。
答案 2 :(得分:0)
拼写错误会更改您的url
表单
{!! Form::open(array('url' => 'admin/companymaster/updateLocation', 'id'=>'updatelocations', 'class' => 'form-horizontal create_form', 'files' => true)) !!}
到
{!! Form::open(array('url' => 'admin/companymaster/updatelocations', 'id'=>'updatelocations', 'class' => 'form-horizontal create_form', 'files' => true)) !!}