【问题标题】:How can I use variables from a form globally in Laravel 8?如何在 Laravel 8 中全局使用表单中的变量?
【发布时间】:2020-11-06 23:45:09
【问题描述】:

我想在全局范围内使用表单中的变量,但我不知道如何使用 Laravel 8

例如,我想在“Alfabeto”中写一个这样的字符串:“a,b,c,d”,当按下“Confirmar”时,我可以将此变量与字符串“a,b,c,d”一起使用任何刀片视图。

<div class="form-group" style="margin-top: 2%;">
<label for="alfabetoAutomata">Alfabeto</label>
<input type="text" class="form-control" name="alfabetoAutomata" id="alfabetoAutomata" title="Debe ingresar el alfabeto como el siguiente ejemplo: a,b,c" pattern="^[a-zA-Z0-9]+(,[a-zA-Z0-9]+)*$" placeholder="Ingrese el alfabeto para los autómatas separados por comas. (Ej: a,b,c)" autocomplete="off" value="<?php echo htmlspecialchars($_GET['alfabetoAutomata'] ?? '', ENT_QUOTES); ?>" required>
</div>

我想全局使用 var $_GET['alfabetoAutomata'],我该怎么做?

希望我已经让自己明白了,非常感谢!

【问题讨论】:

    标签: php laravel forms laravel-8


    【解决方案1】:

    查看 View::share 文档。 https://laravel.com/docs/8.x/views#sharing-data-with-all-views 如果这不是您想要的,那么我建议在您的控制器内部设置一个像这样的会话变量。

     Session::put('foo', 'bar')
    

    foo 上方是变量的名称,bar 是值。现在,当我需要更改 foo 的值时,例如在刀片文件中,我可以这样做。

    {{Session::put('foo','Another Bar')}}
    

    【讨论】:

      猜你喜欢
      • 2021-09-23
      • 2021-08-19
      • 2021-12-18
      • 2019-06-13
      • 2018-01-30
      • 1970-01-01
      • 2013-11-25
      • 1970-01-01
      相关资源
      最近更新 更多