向隐藏的输入Laravel Blade中插入一个值 [英] Insert a value to hidden input Laravel Blade

查看:60
本文介绍了向隐藏的输入Laravel Blade中插入一个值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

How to pass a value to hidden input ?

创建表单:

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

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

I got the form id by url like this :

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

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

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

,控制器为:

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

结果给了我这个错误"没有对模型[App \ Edition]的查询结果."

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

推荐答案

通常,这在Blade模板中使用.

Usually, this is used in Blade templates.

只需将名称和值传递给方法即可.

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')) }}

现在输入具有id属性.

Now the input has an id attribute.

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

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

在控制器方法检查中

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

这篇关于向隐藏的输入Laravel Blade中插入一个值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆