Kamlesh Gupta
Kamlesh Gupta

Reputation: 45

MethodNotAllowedHttpException in RouteCollection.php line 218 in Laravel

I want to use post method in Laravel but it's throwing exception: MethodNotAllowedHttpException in RouteCollection.php line 218

Here is the full error :

in RouteCollection.php line 218
at RouteCollection->methodNotAllowed(array('GET', 'HEAD')) in RouteCollection.php line 205
at RouteCollection->getRouteForMethods(object(Request), array('GET', 'HEAD')) in RouteCollection.php line 158
at RouteCollection->match(object(Request)) in Router.php line 766
at Router->findRoute(object(Request)) in Router.php line 621
at Router->dispatchToRoute(object(Request)) in Router.php line 607
at Router->dispatch(object(Request)) in Kernel.php line 268
at Kernel->Illuminate\Foundation\Http\{closure}(object(Request)) in Pipeline.php line 53
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in CheckForMaintenanceMode.php line 46
at CheckForMaintenanceMode->handle(object(Request), object(Closure)) in Pipeline.php line 137
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 33
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in Pipeline.php line 104
at Pipeline->then(object(Closure)) in Kernel.php line 150
at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 117
at Kernel->handle(object(Request)) in index.php line 53
at require_once('E:\Laravel\myproject\public\index.php') in server.php line 21  

here is my form code:

<div id="education_form">
{{ Form::open(array('method' => 'post','data-parsley-validate')) }}
{{ Form::hidden('user_id', Auth::user()->id, array('id' => 'user_id')) }}


<div class="form-group">
    {{Form::label('school','School')}}<span class="required">*</span>
    {{Form::text('school',null,['class'=>'form-
    control','id'=>'school','placeholder'=>'Enter School Name'])}}
</div>
<div class="form-group">
    {{Form::label('degree','Degree')}}<span class="required">*</span>
    {{Form::text('degree',null,['class'=>'form-
    control','id'=>'degree','placeholder'=>'Enter Degree'])}}
</div>

<div class="form-group">
    {{Form::label('specialization','Specialization')}}
    {{Form::text('specialization',null,['class'=>'form-
    control','id'=>'specialization','placeholder'=>'Enter 
    Specialization'])}}
</div>
{{Form::submit('Save',array('id'=>'saveEducation','class'=>'form-submit btn 
btn-success btn-md pull-right'))}}

{{ Form::close() }}
</div>

I am passing data to ajax using url as below that's why there is no url in form tag.

<script>
var urlSave = '{{ route('save') }}';
</script>

here is my route file:

Route::post('/save', [
'uses' => 'MyController@save',
'as' => 'save'
]); 

Please let me know what mistake I am doing...Thanks!

Upvotes: 1

Views: 963

Answers (2)

AddWeb Solution Pvt Ltd
AddWeb Solution Pvt Ltd

Reputation: 21681

You should try this:

$.ajax({
    url : "{!! route('save') !!}",
    type: "post",
    data : {data:hierarchy.nestable('serialize')},
    success: function(data) {
        //Proceed to success
    },
    error: function (jqXHR, textStatus, errorThrown) {
        //Check for error
    }
});

OR pass action method in form like :

{{ Form::open(array('route' => 'route','method' => 'post','data-parsley-validate')) }}

Upvotes: 1

JYoThI
JYoThI

Reputation: 12085

single quotes ended before the word save and started again after the save it cause

Uncaught SyntaxError: Unexpected identifier

var urlSave = "{{ route('save') }}";

Upvotes: 0

Related Questions