将数据发送到资源方法

Send a data to resources method

我需要将数据发送到方法资源路由

示例:

Route::get('post/{post_type}', 'PostController@index')->where('post_type', '[A-Za-z]+');

但是我不知道怎么在resources route里做

Route::resource('post', 'PostController'); 

并且在使用 link

发送数据时
{{route('post.index',['post_type'=>'news'])}}

URL中显示的内容:

http://127.0.0.1:8000/admin/post?post_type=news

但我需要的是:

http://127.0.0.1:8000/admin/post/news

我解决这个问题的尝试:

Route::resource('post', 'PostController',['parameters'=>['post'=>'post_type']]);

但这只会改变 URL 资源:

发件人:admin/post

至:admin/post_type

我在索引方法中获取这些数据也有问题:

为此,我采取了以下行动:

public function index($post_type)
    { 
        return $post_type;
    }

感谢您的帮助

据我对 Resource Controllers 的了解,您只能 7 fixed URI`s 使用您的资源。

因此,如果您正在调用 index 方法,它具有标准 URI /post。您不能将其更改为 /post/anything

您应该在 URI posts 中使用复数形式的资源。 Route::resource('posts', 'PostController');

因此您无法从 http://127.0.0.1:8000/admin/post/news url.

访问 index 方法