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/任何内容
您应该在URIposts
中使用资源的复数版本。
Route::resource('posts','PostController')代码>
因此,您无法从http://127.0.0.1:8000/admin/post/news
url.这意味着我不应该使用资源控制器?@saeidyaghoobi您可以,但您已经使用了预定义的URI来访问预定义的资源方法。此数据应发送到所有方法。解决方案是什么?@saeidyaghoobi是常数数据吗?它与所有方法共享。我使用“post_type”对显示和创建的帖子进行排序,就像wordpress中的自定义post_type一样