If you want to access $cat
variable everywhere i.e in all controllers and views you should share it as below:
protected $cat;
public function __construct()
{
$this->cat = Categories::get()->first();
View::share('site_settings', $this->cat);
}
I will assume that you are using BaseController
constructor. Now if your controllers extend this BaseController
, they can just access the category using $this->cat
.
Second Method:
You can also give a try using Config class. All you need to do is add the following code within boot
method of app/Providers/AppServiceProvider.php
Config::set(['user' => ['name' => 'John Doe']]);
Then any where in your project you can fetch the value by using Config::get('user.name');