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)); }
/** * Get Collection path for same type of entities. Typically generated by pluralizing class name. * Used when creating new objects. ie:- POST /users */ public function getCollectionPath() { if (!$this->collection_path) { return Str::collectionPath(get_called_class()); } else { return $this->collection_path; } }
public function testCollectionPath() { $this->assertEquals('users', Str::collectionPath('Foo\\User')); $this->assertEquals('users', Str::collectionPath('Foo\\Bar\\User')); }