Exemple #1
0
 /** @test **/
 public function it_fetches_the_field_of_the_component()
 {
     $this->createComponent('pages', function ($component) {
         $component->string('title');
     });
     $component = Component::byName('pages');
     $this->assertEquals('title', $component->field('title')->name);
 }
Exemple #2
0
 /**
  * Create a new model through eloquent model for mocking.
  *
  * @param  string  $table
  * @param  array  $values
  * @return void
  */
 public function insertOn(string $table, array $field = [])
 {
     $component = Component::where('name', $table)->first();
     $instance = $component->instances()->save(new Instance());
     foreach ($field as $attribute => $value) {
         $field = $component->fields()->where(['name' => $attribute])->first();
         if (!$field) {
             $field = $component->fields()->save(new Field(['name' => $attribute]));
         }
         $instance->values()->save(new Value(['content' => $value, 'field_id' => $field->id]));
     }
 }
Exemple #3
0
 /**
  * Create or find the given component.
  *
  * @param  string  $name
  * @return Component
  */
 private function newComponent(string $name)
 {
     return Component::firstOrCreate(['name' => $name]);
 }
Exemple #4
0
 /**
  * Build the schema.
  *
  * @return \Illuminate\Database\Eloquent\Collection
  */
 public function build()
 {
     return $this->component->fields()->saveMany($this->fields);
 }
Exemple #5
0
 /**
  * Open a connection to the component.
  *
  * @param  string  $name
  * @return Component
  */
 private function openConnection(string $name)
 {
     return EloquentComponent::byName($name);
 }