/**
  * Set and return current locale
  *
  * @param  string $locale Locale to set the App to (optional)
  *
  * @return string                    Returns locale (if route has any) or null (if route does not have a locale)
  */
 public function setLocale($locale = null)
 {
     if (empty($locale) || !is_string($locale)) {
         // If the locale has not been passed through the function
         // it tries to get it from the first segment of the url
         $locale = $this->request->segment(1);
     }
     if (!empty($this->supportedLocales[$locale])) {
         $this->currentLocale = $locale;
     } else {
         // if the first segment/locale passed is not valid
         // the system would ask which locale have to take
         // it could be taken by the browser
         // depending on your configuration
         $locale = null;
         // if we reached this point and hideDefaultLocaleInURL is true
         // we have to assume we are routing to a defaultLocale route.
         if ($this->hideDefaultLocaleInURL()) {
             $this->currentLocale = $this->defaultLocale;
         } else {
             $this->currentLocale = $this->getCurrentLocale();
         }
     }
     //save locale in session
     session('locale', $this->currentLocale);
     $this->app->setLocale($this->currentLocale);
     return $locale;
 }
 /**
  * Set and return current locale
  *
  * @param  string $locale Locale to set the App to (optional)
  *
  * @return string                    Returns locale (if route has any) or null (if route does not have a locale)
  */
 public function setLocale($locale = null)
 {
     if (empty($locale) || !is_string($locale)) {
         // If the locale has not been passed through the function
         // it tries to get it from the first segment of the url
         $locale = $this->request->segment(1);
     }
     if (!empty($this->supportedLocales[$locale])) {
         $this->currentLocale = $locale;
     } else {
         // if the first segment/locale passed is not valid
         // the system would ask which locale have to take
         // it could be taken by the browser
         // depending on your configuration
         $locale = null;
         // if we reached this point and hideDefaultLocaleInURL is true
         // we have to assume we are routing to a defaultLocale route.
         if ($this->hideDefaultLocaleInURL()) {
             $this->currentLocale = $this->defaultLocale;
         } else {
             $this->currentLocale = $this->getCurrentLocale();
         }
     }
     $this->app->setLocale($this->currentLocale);
     // Regional locale such as de_DE, so formatLocalized works in Carbon
     $regional = $this->getCurrentLocaleRegional();
     if ($regional) {
         setlocale(LC_TIME, $regional . '.utf8');
     }
     return $locale;
 }