I use to develop with Drupal. In Drupal there are global variables such as $user or $_view, so you can use these in different modules. I wonder how can I make something like this in Laravel, after the user log in, I can use the global $user in different controller.Except using session is there any other ways to implement this one? Thank you.
1条回答 默认 最新
- dousui6488 2016-07-22 12:21关注
For most constants used globally across the application, storing them in config files is sufficient. It is also pretty simple
Create a new file in the app/config directory. Let's call it constants.php
In there you have to return an array of config values.
return [ 'langs' => [ 'es' => 'www.domain.es', 'en' => 'www.domain.us' // etc ] ];
And you can access them as follows
Config::get('constants.langs'); // or if you want a specific one Config::get('constants.langs.en');
And you can set them as well
Config::set('foo.bar', 'test');
解决 无用评论 打赏 举报