hmm let me see...... no, still not psychic
How can i solve this 404 not found error even when route exist
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
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?
hey some code please. and yeah, @TortleWortle is correct. run that command first.
Okay Here is my route: Route::post('/mappy','locationController@postLocation')->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); }); }
Change your route to
Route::get('/mappy','locationController@postLocation')->name('location');
//Or if your posting some values at the time of page load try this
Route::any('/mappy','locationController@postLocation')->name('location');
I have changed it to Route::any('/mappy','locationController@postLocation')->name('location'); i still have the error
I did do the php artisan route:list and the route exist.
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.
Do you have the debugger turned on?
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\locationController@postLocation | web,auth
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);
}
);
}
you are trying to send lat long with the request but the route is not expecting any parameters so it fails to match
@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)
Please i Need Help !!!!!!!!!!!!!!!!!!!!!!!!!
- You said your route list results in:
POST | mappy | location | App\Http\Cont rollers\locationController@postLocation | web,auththere is space in the middle of the wordCont rollers. I assume it is a mistake done when pasting the text here, but check it out. - Are you running the command in the
http://127.0.0.1:8000or maybe in some sub-directory, for examplehttp://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.
see your route has auth middleware if you are making AJAX request internally, make sure you are sign in. And, if you get 500 Internal Server Error there might be something wrong within your Controller. Post your controller also.
Hi i suggest that place your route on the top of the all routes this is work for me
delete all files in the folder >> project folder >> bootstrap >> cache >> delete all files from this folder.
@mailnike please check the dates on questions
I had the same issue. I reset the .htaccess file and it works fine again.
Please check for your APP_URL if it got more '/' than expected
For those wandering for this, remember to enable the rewrite module with sudo a2enmod rewrite
I have the same issue, in my case I realize that I have a form in a form and sometimes when the inner exist in the view, I click the submit button for the outer form, and it occurs 404 error I move the inner outside, and when they separated the problem has been solved.
Add this to .htaccess in your public folder
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ / [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>
I guess the problem is with the .htaccess file in the public folder, move it to the root directory
@tonystarks whats with the irrelevant answer 4 years after the fact?
.htaccess belongs in the public folder and the public folder should be the document root
@Snapey should this also apply to an _ss_environment file?
write (php artisan optimize) and restart your server
@Ayyan i ty this, but not work in my project
running php artisan optimize solved my issue of 404
If you are using Route::resource this can have undisclosed effects on other routes, don't know why.
Put your routes above any Route::resource
Laravel 10 - even though php artisan route:list shows a route, I was getting "404 not found". Only thing that fixed this was placing my route above the Route::resource for the URL sharing the same prefix.
Run command line php artisan optimize:clear it's work fine for all..
If you have any subdirectory with same name of your route in public folder you get 404. Check this!
Please or to participate in this conversation.