Deb Deb - 2 years ago 115
PHP Question

MethodNotAllowedHttpException in RouteCollection.php line 218: laravel 5.4

i want to add new law details with a form, this form has two buttons like update and cancel.

when i hit on cancel button the form gets cancelled and is redirected to previous page, and when i hit update button without filling form details it asks for validation.

after filling all required details of form, when i hit update button it throws me error as MethodNotAllowedHttpException in RouteCollection.php line 218:

my form is this:

{!! 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>


my route is:

Route::post('admin/companymaster/updatelocations', 'CompanyController@updateLocation');


my controller is:

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();
}


when i submit my form by clicking on update button i get an error page as:
enter image description here

can anyone help me out with this.?

Answer Source

It seems that you are going on the wrong route, and you have an error on url, try this way;

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>
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download