Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 将数据发送到资源方法_Php_Laravel_Laravel 5.6 - Fatal编程技术网

Php 将数据发送到资源方法

Php 将数据发送到资源方法,php,laravel,laravel-5.6,Php,Laravel,Laravel 5.6,我需要向方法资源路由发送数据 例如: Route::get('post/{post_type}', 'PostController@index')->where('post_type', '[A-Za-z]+'); 但我不知道如何使它在资源路线 Route::resource('post', 'PostController'); 当通过链接发送数据时 {{route('post.index',['post_type'=>'news'])}} URL中显示的内容: http:/

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

例如:

Route::get('post/{post_type}', 'PostController@index')->where('post_type', '[A-Za-z]+');
但我不知道如何使它在资源路线

Route::resource('post', 'PostController'); 
当通过链接发送数据时

{{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\u type

我在索引方法中获取此数据时也遇到问题:

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

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

感谢您的帮助

根据我对
资源控制器的了解
,您只能使用
7个固定URI

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

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


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

这意味着我不应该使用资源控制器?@saeidyaghoobi您可以,但您已经使用了预定义的URI来访问预定义的资源方法。此数据应发送到所有方法。解决方案是什么?@saeidyaghoobi是常数数据吗?它与所有方法共享。我使用“post_type”对显示和创建的帖子进行排序,就像wordpress中的自定义post_type一样