/** * Builds a source model * * @param string $name * @param Collection $fields */ public function build($name, Collection $fields = null) { $path = $this->getClassFilePath($name); $tableName = source_table_name($name); $contents = view('_hierarchy::entities.model', ['tableName' => $tableName, 'name' => $this->getClassName($name), 'fields' => $this->makeFields($fields), 'searchableFields' => $this->makeSearchableFields($fields, $tableName), 'mutatables' => $this->makeMutatableFields($fields)])->render(); $this->write($path, $contents); }
/** * @param Builder $query * @param $attribute * @param $direction * @return mixed */ protected function orderQueryBySourceAttribute(Builder $query, $attribute, $direction) { $table = $this->_isTranslationAttribute($attribute) ? $this->sourcesTable : source_table_name($this->getNodeTypeName()); $key = $this->getTable() . '.' . $this->getKeyName(); return $query->join($table . ' as t', 't.node_id', '=', $key)->select('t.id as source_id', 'nodes.*')->groupBy($key)->orderBy('t.' . $attribute, $direction); }
/** * Builds a field migration for a table * * @param string $name * @param string $type * @param bool $indexed * @param string $tableName * @return string */ public function buildFieldMigrationForTable($name, $type, $indexed, $tableName) { $path = $this->getMigrationPath($tableName, $name); $migration = $this->getTableFieldMigrationName($name, $tableName); $contents = view('_hierarchy::migrations.field', ['field' => $name, 'table' => source_table_name($tableName), 'migration' => $migration, 'type' => $this->getColumnType($type), 'indexed' => $indexed])->render(); $this->write($path, $contents); return $this->getMigrationClassPath($migration); }
/** @test */ function it_registers_source_table_name_helper() { $this->assertEquals('ns_projects', source_table_name('project')); }