Tweak relation object

Tweaks #273
This commit is contained in:
Barry vd. Heuvel
2015-10-19 09:31:08 +02:00
parent 11037acfe6
commit 56f89502e3
+8 -6
View File
@@ -11,6 +11,7 @@
namespace Barryvdh\LaravelIdeHelper\Console; namespace Barryvdh\LaravelIdeHelper\Console;
use Illuminate\Console\Command; use Illuminate\Console\Command;
use Illuminate\Database\Eloquent\Relations\Relation;
use Illuminate\Support\Str; use Illuminate\Support\Str;
use Illuminate\Filesystem\Filesystem; use Illuminate\Filesystem\Filesystem;
use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Input\InputOption;
@@ -364,13 +365,14 @@ class ModelsCommand extends Command
) as $relation) { ) as $relation) {
$search = '$this->' . $relation . '('; $search = '$this->' . $relation . '(';
if ($pos = stripos($code, $search)) { if ($pos = stripos($code, $search)) {
$code = substr($code, $pos + strlen($search));
$end = strpos($code, ')->') ?:strpos($code, ');');
if (false !== $end) {
//Resolve the relation's model to a fully-qualified class name.
$relatedModel = '\\' . get_class($model->$method()->getRelated());
if ($relation === "belongsToMany" or $relation === 'hasMany' or $relation === 'morphMany' or $relation === 'morphToMany') { //Resolve the relation's model to a Relation object.
$relationObj = $model->$method();
if ($relationObj instanceof Relation) {
$relatedModel = '\\' . get_class($relationObj->getRelated());
if (in_array($relation, ['belongsToMany', 'hasMany', 'morphMany', 'morphToMany'])) {
//Collection or array of models (because Collection is Arrayable) //Collection or array of models (because Collection is Arrayable)
$this->setProperty( $this->setProperty(
$method, $method,