如何在 Laravel 8 中全局使用表单中的变量?

How can I use variables from a form globally in Laravel 8?

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

例如,我想在“Alfabeto”中写入这样的字符串:“a、b、c、d”,然后在按下“Confirmar”时,我可以将此变量与字符串“a、b、c、d”一起使用任意 blade 次观看。

<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'],我该怎么做?

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

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

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

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

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