@vlauciani I’m not sure what input you want to use globally, but if a user is specifying parameters (i.e. settings) then you could put them in the session, and access them from there.
Jan 26, 2016
8
Level 1
Use $request->input params, globally
Hi all
Starting from a simple URL like this:
http://<host>/?var1=value1&var2=value2
I'm retrieving GET input:
class myController extends Controller
{
public function index(Request $request)
{
. . .
$var1 = $request->input('var1', 'default_value1');
$var2 = $request->input('var2', 'default_value2');
. . .
}
}
I would like to use $var1 and $var2 as a global variable to use it in the entire app.
I tried something like this:
class myController extends Controller
{
public function index(Request $request)
{
. . .
$var1 = $request->input('var1', 'default_value1');
$var2 = $request->input('var2', 'default_value2');
define('var1',$var1);
define('var2',$var2);
. . .
}
}
than I can use it, for example, into the Handler class:
class Handler extends ExceptionHandler
{
. . .
public function render($request, Exception $e)
{
. . .
dd(var1);
. . .
}
}
but I do not like this and i don't think this is the best way.
Thank you, Valentino
Please or to participate in this conversation.