#Splitting routes resulting in errors

34 messages · Page 1 of 1 (latest)

round matrix
#

Since splitting my routes into ordered sub folders my application has not been working, I think it has to do with my route service provider?.... would be much appreciated if someone could take a look

RouteServiceProvider:

half orchid
#

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

ancient wren
#

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

agile wren
ancient wren
agile wren
#

Fair but I find I rarely think to check Kernel.php first

#

Excuse me meant RouteServiceProvider.php

ancient wren
#

Fair, nothing inherently wrong with it, I just prefer to load all my route definitions from the one place

round matrix
#

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

half orchid
#

Can you please actually read the #rules, and format your code?

ancient wren
#

```php
// Your PHP Code
```

agile wren
#

Run php artisan route:list to verify what routes are registered

round matrix
#

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

half orchid
#

Which route is it you’re trying to access in the browser?

round matrix
#

admin/posts/index , admin/posts/create both reply 404

half orchid
round matrix
half orchid
# round matrix

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.

autumn stream
#

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

round matrix
round matrix
#

I can send my post routes if you'd like?

autumn stream
#

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

round matrix
#
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?'

autumn stream
#

What is the exact problem again? What route are you hitting, what response do you get, and what have you done to debug it?

round matrix
#

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