Inheritance: extends Illuminate\Database\Eloquent\Model, use trait Dimsav\Translatable\Translatable
 private function createCountries($countries)
 {
     foreach ($countries as $data) {
         $country = new Country();
         $country->id = $data['id'];
         $country->code = $data['code'];
         $country->save();
     }
 }
示例#2
0
 public function test_whereTranslationLike_filters_by_translation_and_locale()
 {
     Country::create(['code' => 'some-code', 'name' => 'Griechenland']);
     $this->assertSame(2, Country::whereTranslationLike('name', 'Griechen%')->count());
     $result = Country::whereTranslationLike('name', '%riechenlan%', 'de')->get();
     $this->assertSame(1, $result->count());
     $this->assertSame('gr', $result->first()->code);
 }
 /**
  * @test
  */
 public function it_should_hide_attributes_after_to_array()
 {
     $country = Country::find(1);
     $this->assertEquals(true, isset($country->toArray()['name']));
     // it is equivalent to set
     //      protected $hidden = ['name'];
     // in Eloquent
     $country->setHidden(['name']);
     $this->assertEquals(false, isset($country->toArray()['name']));
 }
 /**
  * @test
  */
 public function it_skips_fallback_if_fallback_is_not_defined()
 {
     App::make('config')->set('app.fallback_locale', 'ch');
     $country = Country::find(1);
     $this->assertEquals($country->getTranslation('pl', true)->locale, 'pl');
 }
 public function test_config_overrides_apps_locale()
 {
     $country = Country::find(1);
     App::make('config')->set('translatable.locale', 'de');
     $this->assertSame('Griechenland', $country->name);
 }
 /**
  * @test
  */
 public function it_fakes_isset_for_translated_attributes()
 {
     $country = Country::find(1);
     $this->assertEquals(true, isset($country->name));
 }
示例#7
0
 public function testRunningMigration()
 {
     $country = Country::find(1);
     $this->assertEquals('gr', $country->code);
 }
 public function test_passing_an_empty_array_should_not_delete_translations()
 {
     $country = Country::whereCode('gr')->with('translations')->first();
     $count = count($country->translations);
     $country->deleteTranslations([]);
     $country = Country::whereCode('gr')->with('translations')->first();
     $this->assertSame($count, count($country->translations));
 }
 /**
  * @test
  */
 public function lists_of_translated_fields_with_fallback()
 {
     App::make('config')->set('translatable.fallback_locale', 'en');
     App::setLocale('de');
     $country = new Country();
     $country->useTranslationFallback = true;
     $list = [['id' => '1', 'name' => 'Griechenland'], ['id' => '2', 'name' => 'France']];
     $this->assertEquals($list, $country->listsTranslations('name')->get()->toArray());
 }