How can i solve this 404 not found error even when route exist

Published 1 week ago by enexspecial

I have being trying to solve this issue about this 404 not found error i created a route and it keep giving me this error

Snapey
Snapey
1 week ago (678,595 XP)

hmm let me see...... no, still not psychic

TortleWortle

Is it in a route group with a prefix?

Is your route file cached?

Is it registered with the proper http method?

Does it show up when you do php artisan route:list?

robrogers3

hey some code please. and yeah, @TortleWortle is correct. run that command first.

enexspecial

Okay Here is my route: Route::post('/mappy','[email protected]')->name('location');

Here is my controller: public function postLocation(Request $request) { $lat = $request->lat; $long = $request->lng;

    $map = Mappy::whereBetween('lat', [$lat-0.1,$lat+0.1])->whereBetween('long', [$long-0.1,$long+0.1])->get();

    return $map;
}

Here is my Js file: function searchInformation(lat,long) { $.post("{{URL::to('mappy')}}", {lat:lat, long:long}, function(match){ console.log(match); }); }

RamjithAp

Change your route to

Route::get('/mappy','[email protected]')->name('location');

//Or if your posting some values at the time of page load try this

Route::any('/mappy','[email protected]')->name('location');
enexspecial

I have changed it to Route::any('/mappy','[email protected]')->name('location'); i still have the error

enexspecial

I did do the php artisan route:list and the route exist.

rumm.an
rumm.an
1 week ago (21,850 XP)

Seems like your AJAX is not hitting the correct route. Try this:

function searchInformation(lat,long) { 
    $.post(
          "{{ route('location') }}",  {lat:lat, long:long}, 
           function(match) { 
                console.log(match); 
           }
      );
 }

If this doesn't work, show your routes file and the result for php artisan route:list.

foomasri

Do you have the debugger turned on?

enexspecial

Yes i have my debugger turned on here is the error

http://127.0.0.1:8000/%7B%7Broute('mappy')%7D%7D 404 (Not Found)

and i have done the php artisan route:list

Here is the result;

POST | mappy | location | App\Http\Cont rollers\[email protected] | web,auth

rumm.an
rumm.an
1 week ago (21,850 XP)

if you are sending AJAX in a seperate .js file, there {{ }} dont work because its javascript not Laravel Blade... So, you can try this:

function searchInformation(lat,long) { 
    $.post(
          "/mappy",  {lat:lat, long:long}, 
           function(match) { 
                console.log(match); 
           }
      );
 }
Snapey
Snapey
1 week ago (678,595 XP)

you are trying to send lat long with the request but the route is not expecting any parameters so it fails to match

enexspecial

@Snapey : I have manually entered the lat and long value into the database i want to retrieve the data from the database. Please what is the best way to go about it

@rumm.an : I have tried it and i am getting 500 internal server error and also i tried using api route and i am getting 401 (Unauthorized)

enexspecial

Please i Need Help !!!!!!!!!!!!!!!!!!!!!!!!!

design-studio
  1. You said your route list results in: POST | mappy | location | App\Http\Cont rollers\[email protected] | web,auth there is space in the middle of the word Cont rollers. I assume it is a mistake done when pasting the text here, but check it out.
  2. Are you running the command in the http://127.0.0.1:8000 or maybe in some sub-directory, for example http://127.0.0.1:8000/my_test_app/ ? if so @@rumm.an js points to the wrong url and it won't work, and you'll have to create the url in the js using laravel, like you tried.

Please sign in or create an account to participate in this conversation.