mirror of
https://github.com/barryvdh/laravel-ide-helper.git
synced 2026-08-18 10:07:12 +00:00
Add custom collection support for get and all methods (#903)
* Add custom collection support for get and all methods * Only add get and all when using custom collection * Use static instead of class name * Add missing custom collection test with relation * Use class reference over string Co-Authored-By: Markus Podar <[email protected]> * Fix when using class reference Co-authored-by: Markus Podar <[email protected]>
This commit is contained in:
co-authored by
Markus Podar
parent
18588eacf3
commit
6a27c5df68
@@ -12,6 +12,7 @@ namespace Barryvdh\LaravelIdeHelper\Console;
|
||||
|
||||
use Composer\Autoload\ClassMapGenerator;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Illuminate\Database\Eloquent\Relations\Relation;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Filesystem\Filesystem;
|
||||
@@ -229,6 +230,7 @@ class ModelsCommand extends Command
|
||||
|
||||
$this->getPropertiesFromMethods($model);
|
||||
$this->getSoftDeleteMethods($model);
|
||||
$this->getCollectionMethods($model);
|
||||
$output .= $this->createPhpDocs($name);
|
||||
$ignore[] = $name;
|
||||
$this->nullableColumns = [];
|
||||
@@ -850,6 +852,20 @@ class ModelsCommand extends Command
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates methods that return collections
|
||||
* @param \Illuminate\Database\Eloquent\Model $model
|
||||
*/
|
||||
protected function getCollectionMethods($model)
|
||||
{
|
||||
$collectionClass = $this->getCollectionClass(get_class($model));
|
||||
|
||||
if ($collectionClass !== '\\' . \Illuminate\Database\Eloquent\Collection::class) {
|
||||
$this->setMethod('get', $collectionClass . '|static[]', ['$columns = [\'*\']']);
|
||||
$this->setMethod('all', $collectionClass . '|static[]', ['$columns = [\'*\']']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ReflectionClass $reflection
|
||||
* @return string
|
||||
|
||||
Reference in New Issue
Block a user