/** * Dynamically retrieve the specified model. * * @param string $name * @return Model */ public function __get($name) { return $this->model(Type::modelify($name)); }
public function testModelifyMethod() { $this->assertEquals('GLBatch', Type::modelify('glBatch')); $this->assertEquals('SalesPerson', Type::modelify('salesPerson')); }
/** * Auto-magically fetch relationships. * * @param string $method * @return Builder|Model|null */ protected function getRelatedFromMethod($method) { // If the called method name exists as a property on the model, // assume it is the camel-cased related type and the property // contains the foreign key for a "belongs to" relationship. if ($this->hasProperty($method)) { if (!$this->relationLoaded($method)) { $relatedType = Type::modelify($method); $this->relations[$method] = $this->belongsTo($relatedType, $method); } return $this->relations[$method]; } // Otherwise, the called method name should be a pluralized, // camel-cased related type for a "has many" relationship. $relatedType = Type::modelify(Type::singularize($method)); $foreignKey = Type::camelize($this->type); return $this->hasMany($relatedType, $foreignKey); }