Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for on, onWriteConnection, with on models #1260

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ All notable changes to this project will be documented in this file.
- Use platformName to determine db type when casting boolean types [\#1212 / stockalexander](https://github.com/barryvdh/laravel-ide-helper/pull/1212)

### Added
- Add `on`, `onWriteConnection` and `with` to models [\#1260 / douglasdc3](https://github.com/barryvdh/laravel-ide-helper/pull/1260)
- Add support of variadic parameters in `ide-helper:models` [\#1234 / shaffe-fr](https://github.com/barryvdh/laravel-ide-helper/pull/1234)

### Changed
Expand Down
7 changes: 5 additions & 2 deletions src/Console/ModelsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -588,12 +588,15 @@ public function getPropertiesFromMethods($model)
);
$this->setMethod($name, $builder . '|' . $modelName, $args, $comment);
}
} elseif (in_array($method, ['query', 'newQuery', 'newModelQuery'])) {
} elseif (in_array($method, ['query', 'newQuery', 'newModelQuery', 'on', 'onWriteConnection', 'with'])) {
$builder = $this->getClassNameInDestinationFile($model, get_class($model->newModelQuery()));

$reflection = new \ReflectionMethod($model, $method);

$this->setMethod(
$method,
$builder . '|' . $this->getClassNameInDestinationFile($model, get_class($model))
$builder . '|' . $this->getClassNameInDestinationFile($model, get_class($model)),
$this->getParameters($reflection)
);

if ($this->write_model_external_builder_methods) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@
* @property \Illuminate\Support\Carbon|null $updated_at
* @method static \Illuminate\Database\Eloquent\Builder|Post newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|Post newQuery()
* @method static \Illuminate\Database\Eloquent\Builder|Post on($connection = null)
* @method static \Illuminate\Database\Eloquent\Builder|Post onWriteConnection()
* @method static \Illuminate\Database\Eloquent\Builder|Post query()
* @method static \Illuminate\Database\Eloquent\Builder|Post whereBigIntegerNotNullable($value)
* @method static \Illuminate\Database\Eloquent\Builder|Post whereBigIntegerNullable($value)
Expand Down Expand Up @@ -158,6 +160,7 @@
* @method static \Illuminate\Database\Eloquent\Builder|Post whereUuidNullable($value)
* @method static \Illuminate\Database\Eloquent\Builder|Post whereYearNotNullable($value)
* @method static \Illuminate\Database\Eloquent\Builder|Post whereYearNullable($value)
* @method static \Illuminate\Database\Eloquent\Builder|Post with($relations)
* @mixin \Eloquent
*/
class Post extends Model
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,11 @@
* @method static \Illuminate\Database\Eloquent\Builder|Simple active() Scope a query to only include active users.
* @method static \Illuminate\Database\Eloquent\Builder|Simple newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|Simple newQuery()
* @method static \Illuminate\Database\Eloquent\Builder|Simple on($connection = null)
* @method static \Illuminate\Database\Eloquent\Builder|Simple onWriteConnection()
* @method static \Illuminate\Database\Eloquent\Builder|Simple query()
* @method static \Illuminate\Database\Eloquent\Builder|Simple whereId($value)
* @method static \Illuminate\Database\Eloquent\Builder|Simple with($relations)
* @mixin \Eloquent
*/
class Simple extends Model
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,11 @@
* @method static SimpleCollection|static[] get($columns = ['*'])
* @method static \Illuminate\Database\Eloquent\Builder|Simple newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|Simple newQuery()
* @method static \Illuminate\Database\Eloquent\Builder|Simple on($connection = null)
* @method static \Illuminate\Database\Eloquent\Builder|Simple onWriteConnection()
* @method static \Illuminate\Database\Eloquent\Builder|Simple query()
* @method static \Illuminate\Database\Eloquent\Builder|Simple whereId($value)
* @method static \Illuminate\Database\Eloquent\Builder|Simple with($relations)
* @mixin \Eloquent
*/
class Simple extends Model
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,12 @@
* @property \Carbon\CarbonImmutable|null $updated_at
* @method static \Illuminate\Database\Eloquent\Builder|CustomDate newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|CustomDate newQuery()
* @method static \Illuminate\Database\Eloquent\Builder|CustomDate on($connection = null)
* @method static \Illuminate\Database\Eloquent\Builder|CustomDate onWriteConnection()
* @method static \Illuminate\Database\Eloquent\Builder|CustomDate query()
* @method static \Illuminate\Database\Eloquent\Builder|CustomDate whereCreatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|CustomDate whereUpdatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|CustomDate with($relations)
* @mixin \Eloquent
*/
class CustomDate extends Model
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@
* @property \Illuminate\Support\Carbon|null $updated_at
* @method static \Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\DoesNotGeneratePhpdocWithExternalEloquentBuilder\Builders\PostExternalQueryBuilder|Post newModelQuery()
* @method static \Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\DoesNotGeneratePhpdocWithExternalEloquentBuilder\Builders\PostExternalQueryBuilder|Post newQuery()
* @method static \Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\DoesNotGeneratePhpdocWithExternalEloquentBuilder\Builders\PostExternalQueryBuilder|Post on($connection = null)
* @method static \Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\DoesNotGeneratePhpdocWithExternalEloquentBuilder\Builders\PostExternalQueryBuilder|Post onWriteConnection()
* @method static \Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\DoesNotGeneratePhpdocWithExternalEloquentBuilder\Builders\PostExternalQueryBuilder|Post query()
* @method static \Illuminate\Database\Eloquent\Builder|Post whereBigIntegerNotNullable($value)
* @method static \Illuminate\Database\Eloquent\Builder|Post whereBigIntegerNullable($value)
Expand Down Expand Up @@ -163,6 +165,7 @@
* @method static \Illuminate\Database\Eloquent\Builder|Post whereUuidNullable($value)
* @method static \Illuminate\Database\Eloquent\Builder|Post whereYearNotNullable($value)
* @method static \Illuminate\Database\Eloquent\Builder|Post whereYearNullable($value)
* @method static \Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\DoesNotGeneratePhpdocWithExternalEloquentBuilder\Builders\PostExternalQueryBuilder|Post with($relations)
*/
class Post extends \Eloquent {}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@
* @property-read int|null $regular_has_many_count
* @method static \Illuminate\Database\Eloquent\Builder|Dynamic newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|Dynamic newQuery()
* @method static \Illuminate\Database\Eloquent\Builder|Dynamic on($connection = null)
* @method static \Illuminate\Database\Eloquent\Builder|Dynamic onWriteConnection()
* @method static \Illuminate\Database\Eloquent\Builder|Dynamic query()
* @method static \Illuminate\Database\Eloquent\Builder|Dynamic with($relations)
* @mixin \Eloquent
*/
class Dynamic extends Model
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@
* @method static \Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Factories\CustomSpace\ModelWithCustomNamespaceFactory factory(...$parameters)
* @method static \Illuminate\Database\Eloquent\Builder|ModelWithCustomNamespace newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|ModelWithCustomNamespace newQuery()
* @method static \Illuminate\Database\Eloquent\Builder|ModelWithCustomNamespace on($connection = null)
* @method static \Illuminate\Database\Eloquent\Builder|ModelWithCustomNamespace onWriteConnection()
* @method static \Illuminate\Database\Eloquent\Builder|ModelWithCustomNamespace query()
* @method static \Illuminate\Database\Eloquent\Builder|ModelWithCustomNamespace with($relations)
* @mixin \Eloquent
*/
class ModelWithCustomNamespace extends Model
Expand Down Expand Up @@ -46,7 +49,10 @@ protected static function newFactory()
* @method static \Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Factories\Factories\ModelWithFactoryFactory factory(...$parameters)
* @method static \Illuminate\Database\Eloquent\Builder|ModelWithFactory newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|ModelWithFactory newQuery()
* @method static \Illuminate\Database\Eloquent\Builder|ModelWithFactory on($connection = null)
* @method static \Illuminate\Database\Eloquent\Builder|ModelWithFactory onWriteConnection()
* @method static \Illuminate\Database\Eloquent\Builder|ModelWithFactory query()
* @method static \Illuminate\Database\Eloquent\Builder|ModelWithFactory with($relations)
* @mixin \Eloquent
*/
class ModelWithFactory extends Model
Expand All @@ -65,7 +71,10 @@ class ModelWithFactory extends Model
* @method static \Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Factories\Factories\ModelWithNestedFactoryFactory factory(...$parameters)
* @method static \Illuminate\Database\Eloquent\Builder|ModelWithNestedFactory newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|ModelWithNestedFactory newQuery()
* @method static \Illuminate\Database\Eloquent\Builder|ModelWithNestedFactory on($connection = null)
* @method static \Illuminate\Database\Eloquent\Builder|ModelWithNestedFactory onWriteConnection()
* @method static \Illuminate\Database\Eloquent\Builder|ModelWithNestedFactory query()
* @method static \Illuminate\Database\Eloquent\Builder|ModelWithNestedFactory with($relations)
* @mixin \Eloquent
*/
class ModelWithNestedFactory extends ModelWithFactory
Expand All @@ -85,7 +94,10 @@ class ModelWithNestedFactory extends ModelWithFactory
*
* @method static \Illuminate\Database\Eloquent\Builder|ModelWithoutFactory newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|ModelWithoutFactory newQuery()
* @method static \Illuminate\Database\Eloquent\Builder|ModelWithoutFactory on($connection = null)
* @method static \Illuminate\Database\Eloquent\Builder|ModelWithoutFactory onWriteConnection()
* @method static \Illuminate\Database\Eloquent\Builder|ModelWithoutFactory query()
* @method static \Illuminate\Database\Eloquent\Builder|ModelWithoutFactory with($relations)
* @mixin \Eloquent
*/
class ModelWithoutFactory extends Model
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@
* @property \Illuminate\Support\Carbon|null $updated_at
* @method static \Illuminate\Database\Eloquent\Builder|Post newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|Post newQuery()
* @method static \Illuminate\Database\Eloquent\Builder|Post on($connection = null)
* @method static \Illuminate\Database\Eloquent\Builder|Post onWriteConnection()
* @method static \Illuminate\Database\Eloquent\Builder|Post query()
* @method static \Illuminate\Database\Eloquent\Builder|Post whereBigIntegerNotNullable($value)
* @method static \Illuminate\Database\Eloquent\Builder|Post whereBigIntegerNullable($value)
Expand Down Expand Up @@ -158,6 +160,7 @@
* @method static \Illuminate\Database\Eloquent\Builder|Post whereUuidNullable($value)
* @method static \Illuminate\Database\Eloquent\Builder|Post whereYearNotNullable($value)
* @method static \Illuminate\Database\Eloquent\Builder|Post whereYearNullable($value)
* @method static \Illuminate\Database\Eloquent\Builder|Post with($relations)
* @mixin \Eloquent
*/
class Post extends Model
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@
* @property \Illuminate\Support\Carbon|null $updatedAt
* @method static \Illuminate\Database\Eloquent\Builder|Post newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|Post newQuery()
* @method static \Illuminate\Database\Eloquent\Builder|Post on($connection = null)
* @method static \Illuminate\Database\Eloquent\Builder|Post onWriteConnection()
* @method static \Illuminate\Database\Eloquent\Builder|Post query()
* @method static \Illuminate\Database\Eloquent\Builder|Post whereBigIntegerNotNullable($value)
* @method static \Illuminate\Database\Eloquent\Builder|Post whereBigIntegerNullable($value)
Expand Down Expand Up @@ -158,6 +160,7 @@
* @method static \Illuminate\Database\Eloquent\Builder|Post whereUuidNullable($value)
* @method static \Illuminate\Database\Eloquent\Builder|Post whereYearNotNullable($value)
* @method static \Illuminate\Database\Eloquent\Builder|Post whereYearNullable($value)
* @method static \Illuminate\Database\Eloquent\Builder|Post with($relations)
* @mixin \Eloquent
*/
class Post extends Model
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@
* @property \Illuminate\Support\Carbon|null $updated_at
* @method static \Illuminate\Database\Eloquent\Builder|Post newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|Post newQuery()
* @method static \Illuminate\Database\Eloquent\Builder|Post on($connection = null)
* @method static \Illuminate\Database\Eloquent\Builder|Post onWriteConnection()
* @method static \Illuminate\Database\Eloquent\Builder|Post query()
* @method static \Illuminate\Database\Eloquent\Builder|Post whereBigIntegerNotNullable($value)
* @method static \Illuminate\Database\Eloquent\Builder|Post whereBigIntegerNullable($value)
Expand Down Expand Up @@ -158,6 +160,7 @@
* @method static \Illuminate\Database\Eloquent\Builder|Post whereUuidNullable($value)
* @method static \Illuminate\Database\Eloquent\Builder|Post whereYearNotNullable($value)
* @method static \Illuminate\Database\Eloquent\Builder|Post whereYearNullable($value)
* @method static \Illuminate\Database\Eloquent\Builder|Post with($relations)
* @mixin \Eloquent
*/
final class Post extends Model
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@
* @method static \Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithExternalEloquentBuilder\Builders\PostExternalQueryBuilder|Post isStatus(string $status)
* @method static \Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithExternalEloquentBuilder\Builders\PostExternalQueryBuilder|Post newModelQuery()
* @method static \Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithExternalEloquentBuilder\Builders\PostExternalQueryBuilder|Post newQuery()
* @method static \Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithExternalEloquentBuilder\Builders\PostExternalQueryBuilder|Post on($connection = null)
* @method static \Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithExternalEloquentBuilder\Builders\PostExternalQueryBuilder|Post onWriteConnection()
* @method static \Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithExternalEloquentBuilder\Builders\PostExternalQueryBuilder|Post query()
* @method static \Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithExternalEloquentBuilder\Builders\PostExternalQueryBuilder|Post whereBigIntegerNotNullable($value)
* @method static \Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithExternalEloquentBuilder\Builders\PostExternalQueryBuilder|Post whereBigIntegerNullable($value)
Expand Down Expand Up @@ -166,6 +168,7 @@
* @method static \Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithExternalEloquentBuilder\Builders\PostExternalQueryBuilder|Post whereUuidNullable($value)
* @method static \Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithExternalEloquentBuilder\Builders\PostExternalQueryBuilder|Post whereYearNotNullable($value)
* @method static \Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithExternalEloquentBuilder\Builders\PostExternalQueryBuilder|Post whereYearNullable($value)
* @method static \Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithExternalEloquentBuilder\Builders\PostExternalQueryBuilder|Post with($relations)
* @method static \Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithExternalEloquentBuilder\Builders\PostExternalQueryBuilder|Post withBool(?bool $booleanVar)
* @method static \Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithExternalEloquentBuilder\Builders\PostExternalQueryBuilder|Post withBoolDifferently(?bool $booleanVar)
* @method static \Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithExternalEloquentBuilder\Builders\PostExternalQueryBuilder|Post withBoolTypeHinted(bool $booleanVar)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@
* @method static PostExternalQueryBuilder|Post isStatus(string $status)
* @method static PostExternalQueryBuilder|Post newModelQuery()
* @method static PostExternalQueryBuilder|Post newQuery()
* @method static PostExternalQueryBuilder|Post on($connection = null)
* @method static PostExternalQueryBuilder|Post onWriteConnection()
* @method static PostExternalQueryBuilder|Post query()
* @method static PostExternalQueryBuilder|Post whereBigIntegerNotNullable($value)
* @method static PostExternalQueryBuilder|Post whereBigIntegerNullable($value)
Expand Down Expand Up @@ -162,6 +164,7 @@
* @method static PostExternalQueryBuilder|Post whereUuidNullable($value)
* @method static PostExternalQueryBuilder|Post whereYearNotNullable($value)
* @method static PostExternalQueryBuilder|Post whereYearNullable($value)
* @method static PostExternalQueryBuilder|Post with($relations)
* @method static PostExternalQueryBuilder|Post withBool(?bool $booleanVar)
* @method static PostExternalQueryBuilder|Post withBoolDifferently(?bool $booleanVar)
* @method static PostExternalQueryBuilder|Post withBoolTypeHinted(bool $booleanVar)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithForcedFqn\Models\Post newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithForcedFqn\Models\Post newQuery()
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithForcedFqn\Models\Post null(string $unusedParam)
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithForcedFqn\Models\Post on($connection = null)
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithForcedFqn\Models\Post onWriteConnection()
* @method static \Illuminate\Database\Query\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithForcedFqn\Models\Post onlyTrashed()
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithForcedFqn\Models\Post query()
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithForcedFqn\Models\Post whereBigIntegerNotNullable($value)
Expand Down Expand Up @@ -164,6 +166,7 @@
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithForcedFqn\Models\Post whereUuidNullable($value)
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithForcedFqn\Models\Post whereYearNotNullable($value)
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithForcedFqn\Models\Post whereYearNullable($value)
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithForcedFqn\Models\Post with($relations)
* @method static \Illuminate\Database\Query\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithForcedFqn\Models\Post withTrashed()
* @method static \Illuminate\Database\Query\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithForcedFqn\Models\Post withoutTrashed()
* @mixin \Eloquent
Expand Down
Loading