Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

1/1 NotFoundHttpException in Controller.php line 268: Controller method not found. in laravel 5

I am trying to post some data into laravel controller using jquery ajax, but it shows error

"1/1 NotFoundHttpException in Controller.php line 268: Controller method not found."

and in console is throws

"NetworkError: 404 Not Found "

here is my code below:

in routes.php

Route::controller('contact', 'ContactController');
Route::post('searchDependency','ContactController@postSearchDependency');

ContactController.php

public function postSearchDependency(){

    //dd('hello');
}

ajax into index.blade.php

$('#deleteRecord').click(function(){

    var total = $('input[class="ids"]:checkbox:checked').length;
    var ContactId=[];
    $('input[class="ids"]:checked').each(function() {
       ContactId.push($(this).val());
    });
    //alert(ContactId);
    $.ajax({
        type: 'POST',
        data: 'contactId: ContactId',
        url: '<?php echo URL::to('contact/searchDependency')?>',         
            success: function(contacts){                
        }          
    }); 

});

i already posted data using ajax to different method of another controller successfully this way, i already tried the possible solutions, but don't know what happens in this case, please anyone helps me out.

like image 601
user-4653387 Avatar asked Nov 27 '25 13:11

user-4653387


1 Answers

Assuming that the routes.php file contains the line:

Route::controller('contact', 'ContactController');

and your ContactController has the following function defined:

public function postSearchDependency() {
    dd('hello');
}

Then this function would be called by a post request to the url contact/search-dependency instead of contact/searchDependency

This is due to transformation of CamelCase function names to more friendly and readable URL's when using Route::controller.

If you additionally define a direct route to your controller methode like:

Route::post('searchDependency','ContactController@postSearchDependency');

This route gets called directly by searchDependency in the URL (without contact before).

You can always check your existing routes and urls by typing

php artisan route:list

in your terminal.

like image 198
shock_gone_wild Avatar answered Nov 29 '25 03:11

shock_gone_wild



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!