Changeset View
Changeset View
Standalone View
Standalone View
src/app/Console/ObjectRelationListCommand.php
Show First 20 Lines • Show All 61 Lines • ▼ Show 20 Lines | public function handle() | ||||
$result = call_user_func([$object, $this->objectRelation]); | $result = call_user_func([$object, $this->objectRelation]); | ||||
} elseif (property_exists($object, $this->objectRelation)) { | } elseif (property_exists($object, $this->objectRelation)) { | ||||
$result = $object->{"{$this->objectRelation}"}; | $result = $object->{"{$this->objectRelation}"}; | ||||
} else { | } else { | ||||
$this->error("No such relation {$this->objectRelation}"); | $this->error("No such relation {$this->objectRelation}"); | ||||
return 1; | return 1; | ||||
} | } | ||||
if ($result instanceof \Illuminate\Database\Eloquent\Collection) { | // Convert query builder into a collection | ||||
$result->each( | if ($result instanceof \Illuminate\Database\Eloquent\Relations\Relation) { | ||||
function ($entry) { | $result = $result->get(); | ||||
$this->info($this->toString($entry)); | |||||
} | |||||
); | |||||
} elseif ($result instanceof \Illuminate\Database\Eloquent\Relations\Relation) { | |||||
$result->each( | |||||
function ($entry) { | |||||
$this->info($this->toString($entry)); | |||||
} | } | ||||
); | |||||
} elseif (is_array($result)) { | // Print the result | ||||
if ( | |||||
($result instanceof \Illuminate\Database\Eloquent\Collection) | |||||
|| is_array($result) | |||||
) { | |||||
foreach ($result as $entry) { | foreach ($result as $entry) { | ||||
$this->info($this->toString($entry)); | $this->info($this->toString($entry)); | ||||
} | } | ||||
} else { | } else { | ||||
$this->info($this->toString($result)); | $this->info($this->toString($result)); | ||||
} | } | ||||
} | } | ||||
} | } |