向隐藏输入 Laravel Blade 插入一个值

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/39314789/
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-08 17:30:30  来源:igfitidea点击:

Insert a value to hidden input Laravel Blade

laravellaravel-5

提问by Ariando Miller

How to pass a value to hidden input ?

如何将值传递给隐藏输入?

Create form :

创建表格:

@if (isset($id))
    {!! Form::hidden('edition', $id) !!}
@endif

I got the form id by url like this :

我通过 url 获得了表单 ID,如下所示:

<a href="../journal/create?edition={{$edition->id}}" class="btn btn-primary">Add Journal</a>

( when I click Add Journal button it will shows a create form with edition id at the url)

(当我单击“添加日志”按钮时,它将在 URL 中显示一个带有版本 ID 的创建表单)

and the controller is :

控制器是:

$id = $request->get('edition');
        $journal = Edition::findOrFail($id)->journal()->create($input);

The result gave me this error "No query results for model [App\Edition]."

结果给了我这个错误“ No query results for model [App\Edition].

回答by Jarvis

Usually, this is used in Blade templates.

通常,这用于 Blade 模板。

Just pass the name and value to the method.

只需将名称和值传递给方法。

{{ Form::hidden('invisible', 'secret') }}

This creates a very simple element which looks like the following.

这将创建一个非常简单的元素,如下所示。

<input name="invisible" type="hidden" value="secret">

To add other attributes, pass a third argument to the method. This third argument must be an array.

要添加其他属性,请将第三个参数传递给该方法。第三个参数必须是一个数组。

{{ Form::hidden('invisible', 'secret', array('id' => 'invisible_id')) }}

Now the input has an id attribute.

现在输入有一个 id 属性。

<input id="invisible_id" name="invisible" type="hidden" value="secret">

Check out : Creating a Hidden Input Field

签出:创建隐藏的输入字段



If still not work check you project have Laravel Collectiveinstalled

如果仍然不起作用,请检查您的项目是否已Laravel Collective安装

In controller method check

在控制器方法检查中

public function store(Request $request)
{
    $name = $request->input('name');
}

回答by danoj.I

you can do this with the help of blade <input type="hidden" value="{{$user->id}}" name="user_id">

你可以在刀片的帮助下做到这一点 <input type="hidden" value="{{$user->id}}" name="user_id">