如何在 Laravel 中的 Input::all() 之后附加额外的值

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16773820/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 07:49:44  来源:igfitidea点击:

How to attach extra values after Input::all() in Laravel

phplaravel

提问by HymanpotK

There's a comment form in page http://localhost/posts/post_id
When I submit the form, I want to attach the post_idvalue to Input::all()since the form doesn't include the input field for post_id. And the column name in comment table for post_id is called post_id,the route to create the comment is comments.store
Any idea? Thanks!

页面中有一个评论表单http://localhost/posts/post_id
当我提交表单时,我想post_id附加值,Input::all()因为表单不包含post_id. 并且 post_id 的评论表中的列名被称为post_id,创建评论的路线是comments.store
任何想法?谢谢!

回答by ipalaus

I think this should work: Input::merge(array('post_id' => $post_id));

我认为这应该有效: Input::merge(array('post_id' => $post_id));

回答by Phill Sparks

How about this...

这个怎么样...

function store($post_id)
{
    $data = Input::all();

    $comment = new Comment($data);
    $comment->post_id = $post_id;
    $comment->save();
}

回答by Mohamed Kawsara

Just use this:

只需使用这个:

Request::instance()->query->set('key','value');

Request::instance()->query->set('key','value');