/** @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); }
/** * 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])); } }
/** * Create or find the given component. * * @param string $name * @return Component */ private function newComponent(string $name) { return Component::firstOrCreate(['name' => $name]); }
/** * Build the schema. * * @return \Illuminate\Database\Eloquent\Collection */ public function build() { return $this->component->fields()->saveMany($this->fields); }
/** * Open a connection to the component. * * @param string $name * @return Component */ private function openConnection(string $name) { return EloquentComponent::byName($name); }