i've ever asked this question before in codeigniter, now I want to ask about this in laravel.
I want to set a global variable for custom helpers, models, and controllers the variable is got from database result..
Here is the example:
don't know where to put the variable
$data= DB::table('categories')->where('id', '2')->first();
$this->product_var = $data->product; **//main global variable**
custom helper
function test() {
if($this->product_var=="product name") {
}
}
my controller
function index() {
echo $this->product_var;
}
my model
function get_data() {
echo $this->product_var;
}
As you can see my scripts above, $this->product_var
is almost used for custom helper
, my controller
, and my model
.
in codeigniter we create Globals.php in libraries folder, or just put the variable in core controllers.
Where should i set the global variable?