johndraks21
johndraks21

Reputation: 95

Laravel - Oops no page available

I have a project in Laravel and I have a page with links.

<ul class="nav nav-second-level">
    <li>
        <a href="{{route('admin.posts.index')}}">All Posts</a>
    </li>
    <li>
        <a href="{{route('admin.posts.create')}}">Create Post</a>
    </li>
    <li>
        <a href="{{route('admin.comments.index')}}">All Comments</a>
    </li>
</ul>

The problem I have is that when I click on the link:

<a href="{{route('admin.posts.create')}}">Create Post</a>

I get the error:

Oops no page found

These are my routes:

Route::group(['middleware' => 'admin', 'as' => 'admin.'], function() {

    Route::get('/admin', function(){
        return view('admin.index');
    });

    Route::get('/admin/posts/{slug}', 'AdminPostsController@post')->name('posts.post');

    Route::resource('admin/users', 'AdminUsersController');
    Route::resource('admin/posts', 'AdminPostsController');
    Route::resource('admin/categories', 'AdminCategoriesController');
    Route::resource('admin/media', 'AdminMediasController');
    Route::resource('admin/comments', 'PostCommentsController');
    Route::resource('admin/comment/replies', 'CommentRepliesController');

});

Upvotes: 2

Views: 201

Answers (1)

patricus
patricus

Reputation: 62228

The admin.posts.create route will evaluate to admin/posts/create. The problem, however, is this route definition:

Route::get('/admin/posts/{slug}', 'AdminPostsController@post')->name('posts.post');

Because this route is defined before your admin/posts resource route, admin/posts/create will not match the create resource action, but will instead match the post action, where {slug} evaluates as "create". I'm guessing the "Oops no page found" message is your own error message because your post action is not expecting to handle a "create" slug.

I believe moving that route definition after your resource route definitions (or, at least after the admin/posts resource definition) should resolve your issue.

Upvotes: 1

Related Questions