Merge pull request #10 from awellis13/patch-1

fixed a bug causing the model command to fail on methods that are not re...
This commit is contained in:
Barry vd. Heuvel
2013-05-07 15:15:27 -07:00
@@ -199,15 +199,19 @@ class ModelsCommand extends Command {
$code = substr($code, $begin, strrpos($code, '}') - $begin + 1); $code = substr($code, $begin, strrpos($code, '}') - $begin + 1);
$begin = stripos($code, 'return $this->'); $begin = stripos($code, 'return $this->');
list($relation, $returnModel, $rest) = explode("'", substr($code, $begin+14),3); //"return $this->" is 14 chars $parts = explode("'", substr($code, $begin+14),3); //"return $this->" is 14 chars
$relation = trim($relation, ' ('); if (isset($parts[2]))
{
if($relation === "belongsTo" or $relation === 'hasOne'){ list($relation, $returnModel, $rest) = $parts;
//Single model is returned $relation = trim($relation, ' (');
$this->setProperty($method, $returnModel, true, null);
}elseif($relation === "belongsToMany" or $relation === 'hasMany'){ if($relation === "belongsTo" or $relation === 'hasOne'){
//Collection or array of models (because Collection is Arrayable) //Single model is returned
$this->setProperty($method, '\Illuminate\Database\Eloquent\Collection|'.$returnModel.'[]', true, null); $this->setProperty($method, $returnModel, true, null);
}elseif($relation === "belongsToMany" or $relation === 'hasMany'){
//Collection or array of models (because Collection is Arrayable)
$this->setProperty($method, '\Illuminate\Database\Eloquent\Collection|'.$returnModel.'[]', true, null);
}
}else{ }else{
//Not a relation //Not a relation
} }