#Splitting routes resulting in errors
34 messages · Page 1 of 1 (latest)
Define “not working”.
Also, post code as actual code blocks in the future.
From #rules:
Sharing Code: Please do not take screenshots of code, instead, use triple backticks around your code when pasting into Discord
Also can you show us your routes method? I'd just be putting those Route definitions within the routes method within RouteServiceProvider
Or just straight into boot
Theres not tons
If these are all 'web' routes you can do what breeze does with require https://github.com/laravel/breeze/blob/1.x/stubs/default/routes/web.php
Personally I'm less of a fan of that, its less immediately obvious which route files are being loaded, you've gotta go spelunking
Fair but I find I rarely think to check Kernel.php first
Excuse me meant RouteServiceProvider.php
Fair, nothing inherently wrong with it, I just prefer to load all my route definitions from the one place
Will do next time, apologies. When logging in its was taking me to /home which replied 404 but I changed public const HOME = '/admin'; instead of /home and now it is taking me to correct page . But the real problem is on the main page, when I click 'view all posts' or 'create post' it replies 404 and when clicking on create new user it take me back to whatever the previous url was
Can you please actually read the #rules, and format your code?
```php
// Your PHP Code
```
Run php artisan route:list to verify what routes are registered
I apologize, I will follow rules from now on
I've reviewed my route list and it appears as though the routes I need are there but they my application is still not working? I am sorry if I seem slow with all of this I am still learning laravel
Which route is it you’re trying to access in the browser?
admin/posts/index , admin/posts/create both reply 404
Show the output of:
php artisan route:list --path=admin/posts
How are you registering these routes? Manually? Or using something like Route::resource?
I’m guessing manually since a DELETE route usually doesn’t have /destroy in the URI.
Make sure you have those routes before the /{post} one, as otherwise they will match that one.
And as mentioned, words like index, destroy etc. are not meant to be part of URIs
Yes I'm doing them manually, I'm doing a course and this is how the guy made his url's so I just copied him, this isn't a professional application its just a practice one.
What do you mean by have? I do have them in my routes/web/posts.php
I can send my post routes if you'd like?
If you have both admin/posts/{post} and admin/posts/index, the second one must come before in the routes file, otherwise the first will match the second URI
But (unrelated to your issue), the index route is usually just GET admin/posts
Route::get('posts/index', [App\Http\Controllers\PostController::class, 'index'])->name('post.index');
Route::get('posts', [App\Http\Controllers\PostController::class, 'store'])->name('post.store');
Route::post('posts/create', [App\Http\Controllers\PostController::class, 'create'])->name('post.create');
Route::get('posts/{post}', [App\Http\Controllers\PostController::class, 'show'])->name('post');
Route::patch('posts/{post}/update', [App\Http\Controllers\PostController::class, 'update'])->name('post.update');
Route::delete('posts/{post}/destroy', [App\Http\Controllers\PostController::class, 'destroy'])->name('post.destroy');
Route::get('posts/{post}/edit', [App\Http\Controllers\PostController::class, 'edit'])->middleware('can:view,post')->name('post.edit');
These are my posts routes. I just restarted my pc and it worked for 2 mins and now has stopped could it be a cache problem or something?'
What is the exact problem again? What route are you hitting, what response do you get, and what have you done to debug it?
admin/posts/create and admin/posts/index return 404 page not found. I have not done much debugging as I don't yet know how