### Install laravel-ide-helper Source: https://github.com/barryvdh/laravel-ide-helper/blob/master/README.md Installs the laravel-ide-helper package as a development dependency using Composer. ```bash composer require --dev barryvdh/laravel-ide-helper ``` -------------------------------- ### PhpStorm Meta File Usage Examples Source: https://github.com/barryvdh/laravel-ide-helper/blob/master/README.md Demonstrates how PhpStorm's meta file enables auto-completion for container instances. It shows examples of resolving 'events' and custom classes, and how the argument can be used as a class name when the key is not found. ```php app('events')->fire(); \App::make('events')->fire(); /** @var \Illuminate\Foundation\Application $app */ $app->make('events')->fire(); // When the key is not found, it uses the argument as class name app('App\SomeClass'); // Also works with app(App\SomeClass::class); ``` -------------------------------- ### Model PHPDoc Example Source: https://github.com/barryvdh/laravel-ide-helper/blob/master/README.md Example of generated PHPDoc for a Laravel model, including properties, relationships, and query builder methods. ```php /** * App\Models\Post * * @property integer $id * @property integer $author_id * @property string $title * @property string $text * @property \Illuminate\Support\Carbon $created_at * @property \Illuminate\Support\Carbon $updated_at * @property-read \User $author * @property-read \Illuminate\Database\Eloquent\Collection|\Comment[] $comments * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Post newModelQuery() * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Post newQuery() * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Post query() * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Post whereTitle($value) * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Post forAuthors(\User ...$authors) * … */ ``` -------------------------------- ### Model Mixin PHPDoc Example Source: https://github.com/barryvdh/laravel-ide-helper/blob/master/README.md Example of a mixin PHPDoc annotation generated for a model when using the `--write-mixin` option. ```php /** * … * @mixin IdeHelperPost */ ``` -------------------------------- ### Publish Configuration Source: https://github.com/barryvdh/laravel-ide-helper/blob/master/README.md Publishes the configuration file for the laravel-ide-helper package, allowing customization of implementations and default options. ```bash php artisan vendor:publish --provider="Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider" --tag=config ``` -------------------------------- ### Generate Laravel Facade PHPDocs Source: https://github.com/barryvdh/laravel-ide-helper/blob/master/README.md Generates a _ide_helper.php file with PHPDocs for Laravel Facades, enabling autocompletion. ```php php artisan ide-helper:generate ``` -------------------------------- ### Automate Facade Doc Generation Source: https://github.com/barryvdh/laravel-ide-helper/blob/master/README.md Configures `composer.json` to automatically run the `ide-helper:generate` command after package updates, ensuring up-to-date facade documentation. ```js "scripts": { "post-update-cmd": [ "Illuminate\\Foundation\\ComposerScripts::postUpdate", "@php artisan ide-helper:generate", "@php artisan ide-helper:meta" ] } ``` -------------------------------- ### Generate Laravel Facade Docs Source: https://github.com/barryvdh/laravel-ide-helper/blob/master/README.md Generates the `_ide_helper.php` file for IDE autocompletion of Laravel facades. This command can be automated after dependency updates. ```bash php artisan ide-helper:generate ``` -------------------------------- ### Auto-completion for Factory Builders Source: https://github.com/barryvdh/laravel-ide-helper/blob/master/README.md Enables auto-completion for `factory()->create()` and `factory()->make()` to return the correct model class. Set `include_factory_builders` to `true` in `config/ide-helper.php`. Requires publishing the PhpStorm Meta file. ```php 'include_factory_builders' => true, ``` -------------------------------- ### PHPDocs for Laravel Fluent Methods Source: https://github.com/barryvdh/laravel-ide-helper/blob/master/README.md Enables PHPDocs support for fluent methods in Laravel migrations. After publishing vendor files, set `include_fluent` to `true` in `config/ide-helper.php` and run `php artisan ide-helper:generate`. ```php $table->string("somestring")->nullable()->index(); ``` ```php 'include_fluent' => true, ``` -------------------------------- ### Generate Docs for Macros and Mixins Source: https://github.com/barryvdh/laravel-ide-helper/blob/master/README.md Generates PHPDocs for Laravel macros and mixins, which are added to the `_ide_helper.php` file. This requires type hinting when declaring macros. ```php Str::macro('concat', function(string $str1, string $str2) : string { return $str1 . $str2; }); ``` -------------------------------- ### Generate PHPDocs for Models Source: https://github.com/barryvdh/laravel-ide-helper/blob/master/README.md Generates PHPDocs for Eloquent models based on table columns, relations, getters, and setters. Requires a database connection. Options include writing directly to model files or generating a separate mixin file. ```bash php artisan ide-helper:models "App\Models\Post" ``` -------------------------------- ### Specify Model Directories Source: https://github.com/barryvdh/laravel-ide-helper/blob/master/README.md Defines which Eloquent models to scan for IDE meta-data generation. You can specify individual models or entire directories. The `--dir` option allows scanning directories outside the default `app/models`. ```bash php artisan ide-helper:models "App\Models\Post" "App\Models\User" php artisan ide-helper:models --dir="path/to/models" --dir="app/src/Model" ``` -------------------------------- ### Generate PhpStorm Meta File for Container Instances Source: https://github.com/barryvdh/laravel-ide-helper/blob/master/README.md Generates a PhpStorm meta file to provide IDE support for resolving objects from the IoC Container. This allows for auto-completion of methods on resolved instances. Run `php artisan ide-helper:meta`. ```bash php artisan ide-helper:meta ``` -------------------------------- ### Generate Model PHPDocs Source: https://github.com/barryvdh/laravel-ide-helper/blob/master/README.md Generates or updates PHPDocs for Eloquent models. The -RW flags reset existing PHPDocs and write directly to the model files. --nowrite creates a separate file, and --write-mixin adds a @mixin tag. ```php php artisan ide-helper:models -RW ``` ```php php artisan ide-helper:models --write-eloquent-helper ``` ```php php artisan ide-helper:models --nowrite ``` ```php php artisan ide-helper:models --write-mixin ``` -------------------------------- ### IDE Helper Template Modifications Source: https://github.com/barryvdh/laravel-ide-helper/blob/master/php-templates/README.md These templates are based on the official VS Code extension by Laravel. Key modifications include using 'return' instead of 'echo' and disabling JSON serialization for output. ```PHP // Based on https://github.com/laravel/vs-code-extension // Modifications: // - return instead of echo // - do not serialize to JSON ``` -------------------------------- ### Generate PhpStorm Meta File Source: https://github.com/barryvdh/laravel-ide-helper/blob/master/README.md Generates a PhpStorm meta file for container instances, improving autocompletion within PhpStorm. ```php php artisan ide-helper:meta ``` -------------------------------- ### Eloquent Model Mixins Source: https://github.com/barryvdh/laravel-ide-helper/blob/master/tests/Console/__snapshots__/EloquentCommandTest__testCommand__1.txt This code snippet demonstrates the use of mixins in an abstract Eloquent model class. Mixins allow the model to inherit methods from other classes, providing IDEs with information about available methods for autocompletion. ```PHP /** * @mixin \Eloquent * @mixin \Illuminate\Database\Eloquent\Builder * @mixin \Illuminate\Database\Query\Builder */ abstract class Model implements ``` -------------------------------- ### Implement Model Hooks for Custom Generation Source: https://github.com/barryvdh/laravel-ide-helper/blob/master/README.md Enables extending the model generation process by implementing the `ModelHookInterface`. Custom hooks can add extra information to models on the fly by interacting with the `ModelsCommand` instance, such as setting properties or modifying methods. ```php 'model_hooks' => [ MyCustomHook::class, ], class MyCustomHook implements ModelHookInterface { public function run(ModelsCommand $command, Model $model): void { if (! $model instanceof MyModel) { return; } $command->setProperty('custom', 'string', true, false, 'My custom property'); $command->unsetMethod('method'); $command->setMethod('method', $command->getMethodType($model, '\Some\Class'), ['$param']); } } /** * MyModel * * @property integer $id * @property-read string $custom */ ``` -------------------------------- ### Support `@comment` based on DocBlock Source: https://github.com/barryvdh/laravel-ide-helper/blob/master/README.md Enables the use of a custom `@comment` tag within DocBlocks to provide descriptions for model properties, particularly useful for relations, getters, and setters. This enhances IDE support by adding context to generated properties. ```php class Users extends Model { /** * @comment Get User's full name * * @return string */ public function getFullNameAttribute(): string { return $this->first_name . ' ' . $this->last_name ; } } // => after generate models /** * App\Models\Users * * @property-read string $full_name Get User's full name * … */ ``` -------------------------------- ### Define Custom Relationship Types and Return Types Source: https://github.com/barryvdh/laravel-ide-helper/blob/master/README.md Allows specifying custom relationship types and their return types if they don't follow Laravel's default naming conventions. Use `additional_relation_types` for custom relationship classes and `additional_relation_return_types` to define return types like 'many' or 'morphTo'. ```php 'additional_relation_types' => [ 'externalHasMany' => \My\Package\externalHasMany::class ], 'additional_relation_return_types' => [ 'externalHasMultiple' => 'many' ], ``` -------------------------------- ### Disable Magic `*_count` and `*_exists` Properties Source: https://github.com/barryvdh/laravel-ide-helper/blob/master/README.md Manages the generation of properties for relationship counts and existence checks (e.g., `related_count`, `related_exists`). These are typically generated from `withCount` and `withExists` Eloquent methods. Control this via `write_model_relation_count_properties` and `write_model_relation_exists_properties` config options. ```php 'write_model_relation_count_properties' => false, 'write_model_relation_exists_properties' => false, ``` -------------------------------- ### Ignore Models Source: https://github.com/barryvdh/laravel-ide-helper/blob/master/README.md Allows specifying models to be excluded from IDE meta-data generation. This can be done via a command-line option or by configuring the `ignored_models` array in the `config/ide-helper.php` file. ```bash php artisan ide-helper:models --ignore="App\Models\Post,App\Models\User" ``` ```php 'ignored_models' => [ App\Post::class, Api\User::class ], ``` -------------------------------- ### Disable Magic `where*` Methods Source: https://github.com/barryvdh/laravel-ide-helper/blob/master/README.md Controls the generation of magic `where*` methods for Eloquent models. These methods allow querying by attribute name (e.g., `Post::whereTitle(...)`). Disabling this can be done via the `write_model_magic_where` configuration option. ```php 'write_model_magic_where' => false, ``` -------------------------------- ### Disable Generics Annotations Source: https://github.com/barryvdh/laravel-ide-helper/blob/master/README.md Controls the use of generics annotations in DocBlocks for collections (e.g., `Collection`), a feature introduced in Laravel 9 and supported by PhpStorm 2022.3+. Disable this by setting `use_generics_annotations` to `false` in the configuration. ```php 'use_generics_annotations' => false, ``` -------------------------------- ### Disable Dedicated Eloquent Builder Methods Source: https://github.com/barryvdh/laravel-ide-helper/blob/master/README.md Controls the generation of methods for dedicated Eloquent Query Builders, which allow for creating separate builder classes instead of using local scopes within models. Disable this via the `write_model_external_builder_methods` configuration option. ```php 'write_model_external_builder_methods' => false, ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.