php - How can I use variables from a form globally in Laravel 8?
I want to use a variables from a form globally but I don't know how do it with Laravel 8
<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>
I want to use the var $_GET['alfabetoAutomata']
globally, how I can do it?
I hope I have made myself understood, thank you very much!
Answer
Solution:
Check out the View::share documentation. https://laravel.com/docs/8.x/views#sharing-data-with-all-views If that is not what you are looking for, then I would suggest, inside your controller, set a session variable like this.
Session::put('foo', 'bar')
Above foo is the name of the variable and bar is the value. Now, when I need to change the value of foo, for example in a blade file, I can do so like this.
{{Session::put('foo','Another Bar')}}
Source