LaravelLocalization::getCurrentLocale PHP Method

getCurrentLocale() public static method

Returns current language
public static getCurrentLocale ( ) : string
return string current language
        public static function getCurrentLocale()
        {
            return \Mcamara\LaravelLocalization\LaravelLocalization::getCurrentLocale();
        }

Usage Example

 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $faker = Faker::create();
     // retrieve all the user_ids from DB
     $users = DB::table('users')->pluck('id');
     // create posts for a single user only
     // $users = ['0'=>'34'];
     //echo '<pre>'; print_r($users); echo '</pre>'; exit;
     // retrieve all the taxon_ids from DB
     $taxons = DB::table('blog_taxons')->pluck('id');
     // the following commneted lines add the same user for each post
     //factory(App\Models\Posts\Post::class, 5)->create([
     //    'user_id' => $faker->randomElement($users)
     //]);
     // the following lines add a diferent user for each post
     foreach (range(1, 5) as $index) {
         //the following lines make use of the model factory
         //$post = factory(App\Models\Posts\Post::class)->create([
         //    'user_id' => $faker->randomElement($users)
         //]);
         $post = App\Models\Posts\Post::create(['title' => ucwords(implode(' ', $faker->words(5))), 'is_public' => $faker->boolean, 'identifier' => $faker->slug, 'post_type' => $faker->word, 'content' => implode(' ', $faker->paragraphs(3)), 'content_data' => implode(' ', $faker->paragraphs(3)), 'draft' => implode(' ', $faker->paragraphs(3)), 'producer_name' => $faker->word, 'youtube_code' => $faker->word, 'copyright_holder' => $faker->word, 'reference_link_target' => $faker->word, 'source_of_supply' => $faker->word, 'user_id' => $faker->randomElement($users)]);
         foreach (LaravelLocalization::getSupportedLocales() as $locale => $data) {
             if ($locale != LaravelLocalization::getCurrentLocale()) {
                 $post->translateOrNew($locale);
                 $post->translate($locale)->title = strtoupper($locale) . '::' . ucwords(implode(' ', $faker->words(5)));
                 //$post->translate($locale)->slug         = $faker->slug;
                 $post->translate($locale)->identifier = $faker->slug;
                 $post->translate($locale)->content = implode(' ', $faker->paragraphs(3));
                 $post->translate($locale)->content_data = implode(' ', $faker->paragraphs(3));
                 $post->translate($locale)->draft = implode(' ', $faker->paragraphs(3));
             }
         }
         $post->save();
         if (count($taxons)) {
             $post->taxons()->attach($faker->randomElement($taxons));
         }
     }
 }
All Usage Examples Of LaravelLocalization::getCurrentLocale