public function testSnake() { $values = ['foo' => 'foo', 'foo-bar' => 'foo_bar', 'fooBar' => 'foo_bar', 'foo_bar' => 'foo_bar']; foreach ($values as $value => $expected) { $actual = Str::snake($value); $this->assertSame($expected, $actual, "Did not snake case '{$value}' correctly"); } }
/** * Get the table column to use for the specified search field. * * @param string $field * @param Model $model * @return string */ protected function columnForField($field, Model $model) { /** If there is a custom mapping, return that */ if (isset($this->sortColumns[$field])) { return $this->sortColumns[$field]; } return $model::$snakeAttributes ? Str::snake($field) : Str::camel($field); }
/** * Convert a model key into a resource attribute key. * * @param $modelKey * @return string */ protected function keyForAttribute($modelKey) { return $this->hyphenated ? Str::dasherize($modelKey) : $modelKey; }
/** * Convert a relationship name into the attribute name to get the relationship from the model. * * @param $relationshipName * the relationship name as it appears in the uri. * @return string * the key to use on the model. */ protected function keyForRelationship($relationshipName) { return isset($this->relationships[$relationshipName]) ? $this->relationships[$relationshipName] : Str::camel($relationshipName); }
/** * @return void */ private function normalizeRelationships() { if (is_array($this->normalizedRelationships)) { return; } $this->normalizedRelationships = []; foreach ($this->relationships as $resourceKey => $modelKey) { if (is_numeric($resourceKey)) { $resourceKey = $modelKey; $modelKey = Str::camel($modelKey); } $this->normalizedRelationships[$resourceKey] = $modelKey; } }