Search code examples
phplaravellaravel-3

Laravel3: Variables that has to be set forever


<meta name="description" content="{{ $description }}" />

It is a variable stored in a custom.config.php. That file can be anywhere. (I'm new to Laravel)

How can I ensure Laravel runs it each time? I'm not going to use ->with('description', $description'); every time I call a view.

Looking for something like: {{ Config::get('website_description') }}


Solution

  • You can add that variable to the before route filter:

    Route::filter('before', function()
    {
        //Do stuff before every request to your application...
        $website_description = Config::get('website_description');  
        View::share('website_description', $website_description);
    });
    

    You can then directly access that variable in your view.