From 647ce6904788bb809a2fade3b529a85549f7b7ae Mon Sep 17 00:00:00 2001 From: Andrew Ellis Date: Tue, 7 May 2013 15:53:19 -0600 Subject: [PATCH] fixed a bug causing the model command to fail on methods that are not relationships --- .../LaravelIdeHelper/ModelsCommand.php | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/Barryvdh/LaravelIdeHelper/ModelsCommand.php b/src/Barryvdh/LaravelIdeHelper/ModelsCommand.php index c39b852..aa46415 100644 --- a/src/Barryvdh/LaravelIdeHelper/ModelsCommand.php +++ b/src/Barryvdh/LaravelIdeHelper/ModelsCommand.php @@ -199,15 +199,19 @@ class ModelsCommand extends Command { $code = substr($code, $begin, strrpos($code, '}') - $begin + 1); $begin = stripos($code, 'return $this->'); - list($relation, $returnModel, $rest) = explode("'", substr($code, $begin+14),3); //"return $this->" is 14 chars - $relation = trim($relation, ' ('); - - if($relation === "belongsTo" or $relation === 'hasOne'){ - //Single model is returned - $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); + $parts = explode("'", substr($code, $begin+14),3); //"return $this->" is 14 chars + if (isset($parts[2])) + { + list($relation, $returnModel, $rest) = $parts; + $relation = trim($relation, ' ('); + + if($relation === "belongsTo" or $relation === 'hasOne'){ + //Single model is returned + $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{ //Not a relation }