Why does the Laravel routing order affect the return content?

I just learned the laravel framework and found that the order of routes will affect the content played. Why?
normal code:

Route::get("posts",function (){
    return "index";
});

Route::get("posts/create",function (){
    return "create";
});

Route::get("posts/{post}",function (){
    return "post";
});

exception code:

Route::get("posts",function (){
    return "index";
});

Route::get("posts/{post}",function (){
    return "post";
});

Route::get("posts/create",function (){
    return "create";
});

there is no difference between the two pieces of code, except that the routing order is different. When accessing the post/create route, the exception code returns the contents of posts/ {post} .

Feb.28,2021

first of all, the route will be matched in the route file, and if the match is successful, it will be returned immediately and will not be executed any further.

posts/create satisfies the matching rule of posts/ {post} , so posts/ {post} is put in front, and posts/create will be hit.

Menu