Here is my nav-bar:
<div class="col-md-2">
<ul class="list-group-item">
<li><a href="/posts"><i class="fa fa-fw fa-file</i> All Post</a>
</li>
<li><a href="/posts/create"><i class="fa fa-fw fa-plus-circle"></i> Create New Post</a></li>
<li><a href="/posts/manage"><i class="fa fa-fw fa-tasks"></i> Manage Posts</a></li>
</ul>
</div>
and here is my route.php
Route::group(['prefix' => 'posts'], function(){
Route::get('', 'PostController@index');
Route::get('create', 'PostController@create');
Route::post('confirm', 'PostController@confirmation');
Route::get('{postID}', 'PostController@show');
Route::get('posts/manage', 'PostController@manage');});
I expect when I click on the "Manage Posts" button, it will redirect me to function manage()
in my PostController
.
But when I click on it, it redirects to a view which belongs to storage/framework/views
which is show()
in my PostController
.
I don't know why and how to make it to the right url.
Can somebody help me with this one please?
Thank you.
First of all, your link links to /posts/management
, not /posts/manage
. Second, you already have the prefix posts
for this route-group, so the route posts/manage
will be available under the url /posts/posts/manage
.
You also want to move the manage
route before your {postID}
route, because {postID}
will just catch anything , so the router has to first check the manage-route, and only if it doesn't match, the catch-all route.
And you should control what is accepted as a valid postID
using Route Parameters: Regular Expression Constraints .
Route::get('{postID}', 'PostController@show')->where('id', '[0-9]+');
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.