Tag Archives: localization

Always sending a variable to the view

As we’re building our app, we’re trying to make it international. We are storing the user’s language preference in the Session, but we need to have it as a variable in the views. I stumbled upon this SO post with an easy solution.

class BaseController extends Controller
{
  public function __construct()
  {
    $lang = Session::get('lang');
    View::share('lang', $lang);
  }
}

This makes the variable $lang available in our views. Nice and easy. Just remember to add “use View;” and, in our case, “use Session;” to the controller as well.