Tuesday, March 14, 2017

How can I share 1 variable through out my Laravel application ?

I have a variable.

$key_test = 123456789;

I want to be able to access this 1 variable anywhere in my app even in config files, models, controllers, and views.


I've tried adding it in my boot()

<?php

namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use App\VSE, App\CURL;
use View;

class AppServiceProvider extends ServiceProvider
{
    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {

        $key_test = 123456789;

    }

    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {
        //
    }
}


I've tried to access it in one of my config file . I kept getting null.

<?php

dd($key_test); <---- null

return [ ... ]; 


Questions

How do I access that variable in my config file ?

Did I do it right in my boot() ?

How would one go about and debug this further ?


I'm opening to any suggestions at this moment.

Any hints / suggestions / helps on this be will be much appreciated !



via ihue

Advertisement