public function buildQueryPath() { //ie:- users/1 $caller_path = $this->getCallingModel()->getEntityPath(); //ie:- posts $relatives_path = Str::collectionPath($this->getRelatingModel()); //since it's one to one, relation path should be singular $relatives_path = Str::singular($relatives_path); //ie:- users/1/post return implode('/', array($caller_path, $relatives_path)); }
/** * If attribute has a relationship defined, generate the models * @param string $attribute * @return mixed - depends on the relation. usually single model or collection */ protected function getAttributeRelatedModels($attribute) { $method = Str::camel($attribute); if (method_exists($this, $method)) { if ($relation = $this->{$method}() and $relation instanceof Relation) { return $relation->getFromModel($attribute); } } return false; }
public function testClassNamespace() { $this->assertEquals('Foo\\Bar', Str::classNamespace('Foo\\Bar\\User')); }