Giter Club home page Giter Club logo

laravel-ide-helper's Introduction

IDE Helper Generator for Laravel

Tests Packagist License Latest Stable Version Total Downloads Fruitcake

Complete PHPDocs, directly from the source

This package generates helper files that enable your IDE to provide accurate autocompletion. Generation is done based on the files in your project, so they are always up-to-date.

The 3.x branch supports Laravel 10 and 11. For older version, use the 2.x releases.

Installation

Require this package with composer using the following command:

composer require --dev barryvdh/laravel-ide-helper

Note

If you encounter version conflicts with doctrine/dbal, please try: composer require --dev barryvdh/laravel-ide-helper --with-all-dependencies

This package makes use of Laravels package auto-discovery mechanism, which means if you don't install dev dependencies in production, it also won't be loaded.

If for some reason you want manually control this:

  • add the package to the extra.laravel.dont-discover key in composer.json, e.g.
    "extra": {
      "laravel": {
        "dont-discover": [
          "barryvdh/laravel-ide-helper"
        ]
      }
    }
  • Add the following class to the providers array in config/app.php:
    Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider::class,
    If you want to manually load it only in non-production environments, instead you can add this to your AppServiceProvider with the register() method:
    public function register()
    {
        if ($this->app->isLocal()) {
            $this->app->register(\Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider::class);
        }
        // ...
    }

Note: Avoid caching the configuration in your development environment, it may cause issues after installing this package; respectively clear the cache beforehand via php artisan cache:clear if you encounter problems when running the commands

Usage

Check out this Laracasts video for a quick introduction/explanation!

Note: You do need CodeComplice for Sublime Text: https://github.com/spectacles/CodeComplice

Automatic PHPDoc generation for Laravel Facades

You can now re-generate the docs yourself (for future updates)

php artisan ide-helper:generate

Note: bootstrap/compiled.php has to be cleared first, so run php artisan clear-compiled before generating.

This will generate the file _ide_helper.php which is expected to be additionally parsed by your IDE for autocomplete. You can use the config filename to change its name.

You can configure your composer.json to do this each time you update your dependencies:

"scripts": {
    "post-update-cmd": [
        "Illuminate\\Foundation\\ComposerScripts::postUpdate",
        "@php artisan ide-helper:generate",
        "@php artisan ide-helper:meta"
    ]
},

You can also publish the config file to change implementations (ie. interface to specific class) or set defaults for --helpers.

php artisan vendor:publish --provider="Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider" --tag=config

The generator tries to identify the real class, but if it cannot be found, you can define it in the config file.

Some classes need a working database connection. If you do not have a default working connection, some facades will not be included. You can use an in-memory SQLite driver by adding the -M option.

If you use real-time facades in your app, those will also be included in the generated file using a @mixin annotation and extending the original class underneath the facade.

Note: this feature uses the generated real-time facades files in the storage/framework/cache folder. Those files are generated on-demand as you use the real-time facade, so if the framework has not generated that first, it will not be included in the helper file. Run the route/command/code first and then regenerate the helper file and this time the real-time facade will be included in it.

You can choose to include helper files. This is not enabled by default, but you can override it with the --helpers (-H) option. The Illuminate/Support/helpers.php is already set up, but you can add/remove your own files in the config file.

Automatic PHPDoc generation for macros and mixins

This package can generate PHPDocs for macros and mixins which will be added to the _ide_helper.php file.

But this only works if you use type hinting when declaring a macro.

Str::macro('concat', function(string $str1, string $str2) : string {
    return $str1 . $str2;
});

Automatic PHPDocs for models

If you don't want to write your properties yourself, you can use the command php artisan ide-helper:models to generate PHPDocs, based on table columns, relations and getters/setters.

Note: this command requires a working database connection to introspect the table of each model

By default, you are asked to overwrite or write to a separate file (_ide_helper_models.php). You can write the comments directly to your Model file, using the --write (-W) option, or force to not write with --nowrite (-N).

Alternatively using the --write-mixin (-M) option will only add a mixin tag to your Model file, writing the rest in (_ide_helper_models.php). The class name will be different from the model, avoiding the IDE duplicate annoyance.

Please make sure to back up your models, before writing the info.

Writing to the models should keep the existing comments and only append new properties/methods. It will not update changed properties/methods.

With the --reset (-R) option, the whole existing PHPDoc is replaced, including any comments that have been made.

php artisan ide-helper:models "App\Models\Post"
/**
 * 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)
 * …
 */

With the --write-mixin (-M) option

/**
 * …
 * @mixin IdeHelperPost
 */

Model Directories

By default, models in app/models are scanned. The optional argument tells what models to use (also outside app/models).

php artisan ide-helper:models "App\Models\Post" "App\Models\User"

You can also scan a different directory, using the --dir option (relative from the base path):

php artisan ide-helper:models --dir="path/to/models" --dir="app/src/Model"

You can publish the config file (php artisan vendor:publish) and set the default directories.

Ignore Models

Models can be ignored using the --ignore (-I) option

php artisan ide-helper:models --ignore="App\Models\Post,App\Models\User"

Or can be ignored by setting the ignored_models config

'ignored_models' => [
    App\Post::class,
    Api\User::class
],

Magic where* methods

Eloquent allows calling where<Attribute> on your models, e.g. Post::whereTitle(…) and automatically translates this to e.g. Post::where('title', '=', '…').

If for some reason it's undesired to have them generated (one for each column), you can disable this via config write_model_magic_where and setting it to false.

Magic *_count properties

You may use the ::withCount method to count the number results from a relationship without actually loading them. Those results are then placed in attributes following the <columname>_count convention.

By default, these attributes are generated in the phpdoc. You can turn them off by setting the config write_model_relation_count_properties to false.

Generics annotations

Laravel 9 introduced generics annotations in DocBlocks for collections. PhpStorm 2022.3 and above support the use of generics annotations within @property and @property-read declarations in DocBlocks, e.g. Collection<User> instead of Collection|User[].

These can be disabled by setting the config use_generics_annotations to false.

Support @comment based on DocBlock

In order to better support IDEs, relations and getters/setters can also add a comment to a property like table columns. Therefore a custom docblock @comment is used:

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
 * …
 */

Dedicated Eloquent Builder methods

A new method to the eloquent models was added called newEloquentBuilder Reference where we can add support for creating a new dedicated class instead of using local scopes in the model itself.

If for some reason it's undesired to have them generated (one for each column), you can disable this via config write_model_external_builder_methods and setting it to false.

Custom Relationship Types

If you are using relationships not built into Laravel you will need to specify the name and returning class in the config to get proper generation.

'additional_relation_types' => [
    'externalHasMany' => \My\Package\externalHasMany::class
],

Found relationships will typically generate a return value based on the name of the relationship.

If your custom relationships don't follow this traditional naming scheme you can define its return type manually. The available options are many and morphTo.

'additional_relation_return_types' => [
    'externalHasMultiple' => 'many'
],

Model Hooks

If you need additional information on your model from sources that are not handled by default, you can hook in to the generation process with model hooks to add extra information on the fly. Simply create a class that implements ModelHookInterface and add it to the model_hooks array in the config:

'model_hooks' => [
   MyCustomHook::class,
],

The run method will be called during generation for every model and receives the current running ModelsCommand and the current Model, e.g.:

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

Automatic PHPDocs generation for Laravel Fluent methods

If you need PHPDocs support for Fluent methods in migration, for example

$table->string("somestring")->nullable()->index();

After publishing vendor, simply change the include_fluent line in your config/ide-helper.php file into:

'include_fluent' => true,

Then run php artisan ide-helper:generate, you will now see all Fluent methods recognized by your IDE.

Auto-completion for factory builders

If you would like the factory()->create() and factory()->make() methods to return the correct model class, you can enable custom factory builders with the include_factory_builders line in your config/ide-helper.php file. Deprecated for Laravel 8 or latest.

'include_factory_builders' => true,

For this to work, you must also publish the PhpStorm Meta file (see below).

PhpStorm Meta for Container instances

It's possible to generate a PhpStorm meta file to add support for factory design pattern. For Laravel, this means we can make PhpStorm understand what kind of object we are resolving from the IoC Container. For example, events will return an Illuminate\Events\Dispatcher object, so with the meta file you can call app('events') and it will autocomplete the Dispatcher methods.

php artisan ide-helper:meta
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);

Note: You might need to restart PhpStorm and make sure .phpstorm.meta.php is indexed.

Note: When you receive a FatalException: class not found, check your config (for example, remove S3 as cloud driver when you don't have S3 configured. Remove Redis ServiceProvider when you don't use it).

You can change the generated filename via the config meta_filename. This can be useful for cases where you want to take advantage of PhpStorm's support of the directory .phpstorm.meta.php/: all files placed there are parsed, should you want to provide additional files to PhpStorm.

License

The Laravel IDE Helper Generator is open-sourced software licensed under the MIT license

laravel-ide-helper's People

Contributors

ahmed-aliraqi avatar barryvdh avatar bebnev avatar binotaliu avatar brendt avatar claar avatar domkrm avatar edcoreweb avatar edvordo avatar eidng8 avatar ellisio avatar gummibeer avatar hailwood avatar inxilpro avatar ipaat avatar jeppeknockaert avatar kaloyanyosifov avatar leo108 avatar loilo avatar mfn avatar mgrinspan avatar mr-feek avatar netpok avatar pahan35 avatar pataar avatar sebsept avatar sforward avatar stidges avatar wimski avatar zedentox avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

laravel-ide-helper's Issues

Errors in Session documentation

Session::get and Session::has has wrong return types in the generated ide-helper because laravel uses {@inheritdoc}

This might be hard to resolve, but they are heavily used functions.

Errorhandling with laravel V3 models "Cannot redeclare non static..."

Hi,

this is only an enhancement, not a real issue. As I'm upgrading my laravel framework from V3 to V4, Iinstalled your very handy tools (thank you for them) and ran into this issue: With Eloquent models V3 you have to declare the table property as public static, now with V4 as protected. If you are not aware of this, php artisan ide-helper:models your-model leads to a 'nice' PHP Fatal error: Cannot redeclare non static Illuminate\Database\Eloquent\Model::$table as static Your-model::$table in ....
Maybe you could add a warning in your readme. And if not, from now on everybody else will know how to solve the error by themselfs :-)

Happy coding

No longer working for Session Facade.

The session Facade has been updated, so now we can longer access any of the methods on the session class as all the methods now reside in SessionManager which is done through __call the _ide_helper.php is now

class Session extends Illuminate\Support\Facades\Session{
/**
 * Create a new manager instance.
 *
 * @param \Illuminate\Foundation\Application  $app
 * @return void
 * @static 
 */
 public static function __construct($app){
    //Method inherited from Illuminate\Support\Manager
     Illuminate\Session\SessionManager::__construct($app);
 }

/**
 * Get a driver instance.
 *
 * @param string  $driver
 * @return mixed
 * @static 
 */
 public static function driver($driver = null){
    //Method inherited from Illuminate\Support\Manager
    return Illuminate\Session\SessionManager::driver($driver);
 }

/**
 * Register a custom driver creator Closure.
 *
 * @param string   $driver
 * @param Closure  $callback
 * @return void
 * @static 
 */
 public static function extend($driver, $callback){
    //Method inherited from Illuminate\Support\Manager
     Illuminate\Session\SessionManager::extend($driver, $callback);
 }

/**
 * Get all of the created "drivers".
 *
 * @return array
 * @static 
 */
 public static function getDrivers(){
    //Method inherited from Illuminate\Support\Manager
    return Illuminate\Session\SessionManager::getDrivers();
 }

/**
 * Dynamically call the default driver instance.
 *
 * @param string  $method
 * @param array   $parameters
 * @return mixed
 * @static 
 */
 public static function __call($method, $parameters){
    //Method inherited from Illuminate\Support\Manager
    return Illuminate\Session\SessionManager::__call($method, $parameters);
 }

}

namespace error

Hi Im using platform 2 which is Laravel4 with extensions and a few other bit's, A extensions are workbench bundles that can sit in the workbench folder or a new root folder at the same level as laravel app folder call "extension" which are namespaced bundles that can contain any thing you can put in the app folder . so I have a extension called apps4u/mobile-manager/ which has a models folder with some models in it when I pass in the namespace of path the the models it keeps giving me a error saying that it can not find the class .

Support Model scope arguments

I LOVE ide-helper:model -W -- thank you so much! Makes PhpStorm a dream come true.

Right now, ide-helper:model ignores scope arguments:

/**
 * @method static version()
 */
function scopeVersion($query, $version=null) {
}

It would be cool if it would grab the arguments as well:

/**
 * @method static version($version=null)
 */
function scopeVersion($query, $version=null) {
}

'Class not found' error message

1st: many thanks for 2 very useful tools!

After running
artisan ide-helper:generate
its possible to get this error message when class not found:

Class Acme\SomeClass is not found.
A new helper file was written to _ide_helper.php

in such case it would be helpful for ide-helper to spit out any relevant file+line

thanks for listening

[Request] Parse bootstrap files for defined Macros

Hi Barry,

Just a [Request]

Parse bootstrap files for defined Macros

Example Macro I have in Bootstrap/start.php

Html::macro('linkButton', function($url, $label, $buttonType = 'primary', $glyph = '', $size = 'md')
{
    return sprintf('<button type="button" class="btn btn-%s btn-%s"
        onclick="window.open(\'%s\',\'_self\')">
      <span class="glyphicon glyphicon-%s"></span> %s
    </button>',$buttonType,$size,$url,$glyph,$label);
});

Thanks,
Chris :-)

illuminate/support 4.0.x -> no matching package found.

I am getting the following error with composer

X@ludjer-virtual-machine:/var/www/ldcextra$ composer install
Loading composer repositories with package information
Installing dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.

Problem 1
- Installation request for barryvdh/laravel-ide-helper dev-master -> satisfiable by barryvdh/laravel-ide-helper dev-master.
- barryvdh/laravel-ide-helper dev-master requires illuminate/support 4.0.x -> no matching package found.

Potential causes:

  • A typo in the package name
  • The package is not available in a stable-enough version according to your minimum-stability setting
    see hxxps://groups.google.com/d/topic/composer-dev/_g3ASeIFlrc/discussion for more details.

Read hxxp://getcomposer.org/doc/articles/troubleshooting.md for further common problems.

Namespace not found

I am using the latest version of ide-helper with Laravel 4.1.16 and ide-helper generated the file: http://pastebin.com/SJjU6zgH

I have tried both Sublime Text and Phpstorm and both give ma an error when attempting to use intellisense on a model that extends from LarvelBook\Ardent\Ardent. Subtime Text gives me this error:
WARNING - codeintel] could not resolve first part of '\LaravelBook\Ardent\Ardent'
PhpStorm states the the namesapce Ardent is undefined.

However, the class Ardent is available in _ide_helper.php:
class Ardent extends LaravelBook\Ardent\Ardent{
}

composer can't solve dependencies.

Hi,

Laravel 4.1 's composer.json changed to minimum-stability": "stable". By this change, Composer can't solve some dependency.

Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - barryvdh/laravel-debugbar dev-master requires maximebf/debugbar dev-master -> satisfiable by maximebf/debugbar[dev-master].
    - barryvdh/laravel-debugbar dev-master requires maximebf/debugbar dev-master -> satisfiable by maximebf/debugbar[dev-master].
    - Removal request for maximebf/debugbar == 9999999-dev
    - Installation request for barryvdh/laravel-debugbar dev-master -> satisfiable by barryvdh/laravel-debugbar[dev-master].

freshTimestamp() static issue?

First off, love this helper! Makes developing Laravel 4 apps so much easier :)

However, in one of my models I'm overriding the freshTimestamp() function Taylor added to Eloquent. This method is not static.

However, PhpStorm is complaining with this error:

Can not make static method Eloquent::freshTimestamp() non static

In my _ide_helper.php I see the following:

    /**
     * Get a fresh timestamp for the model.
     *
     * @static
     * @return mixed
     */
     public static function freshTimestamp(){
        return static::$root->freshTimestamp();
     }

However, I notice that all Eloquent methods are static in the helper. So this really applies to any method you override in your models.

I'm not really sure how to get around this issue as I haven't really digested your helper logic yet. Any thoughts?

Cheers,
-Andrew

Exception: Class auth does not exist

composer.json:

"barryvdh/laravel-ide-helper": "1.*"

and got this message below:

➜  src  php artisan ide-helper:generate
Exception: Class auth does not exist
Skipping Illuminate\Support\Facades\Auth.
Exception: Class auth does not exist
Skipping Illuminate\Support\Facades\Password.
A new helper file was written to _ide_helper.php

Can't install laravel with minimum-stability:stable because of laravel-ide-helper dependecy on phpdocumentor/reflection-docblock dev

I can't install laravel with minimum-stability:stable because of a laravel-ide-helper dependecy on phpdocumentor/reflection-docblock dev.

When running composer update I get the error :

barryvdh/laravel-ide-helper v1.1.2 requires
phpdocumentor/reflection-docblock dev-master#6d705c1a0f9e2a6d73d2e9ec0e538b9dfaf4315f
-> satisfiable by phpdocumentor/reflection-docblock[dev-master].

It would be great if you changed your composer.json to reference a stable version of phpdocumentor/reflection-docblock.

Error when using models on Laravel 4.1

I get the following error when using the models functionality on Laravel 4.1

PHP Fatal error:  Class 'Doctrine\DBAL\Driver\PDOMySql\Driver' not found in C:\apache\htdocs\app_name\vendor\laravel\framework\src\Illuminate\Database\MySqlConnection.php on line 59
{"error":{"type":"Symfony\\Component\\Debug\\Exception\\FatalErrorException","message":"Class 'Doctrine\\DBAL\\Driver\\PDOMySql\\Driver' not found","file":"C:\\apache\\htdocs\\app_name\\vendor\\l
aravel\\framework\\src\\Illuminate\\Database\\MySqlConnection.php","line":59}}

How to generate documentation for own facades

I included the ide-helper and published it in the config app/config/packages/barryvdh/laravel-ide-helper/config.php. In config file i set:

// ...
'extra' => array(
    // Artisan, Eloquent, Session...
    'MinkSession' => array('Behat\Mink\Session', 'Behat\Mink\Driver\Selenium2Driver')
),
// ...

I run php artisan clear-compiled && php artisan ide-helper:generate.
Now I expect that the documentation will be generated in the file _ide_helper.php... but it is not( Why?
I misunderstood the essence of documentation generator? Maybe I did not use the correct configuration? What am I doing wrong?
Thanks.

query scopes for models

is it possible to have autocompletion query scopes methods while using on model eg.
User::active()->get();

Nothing Happens

Hello,

I have followed the steps outlined in the README and code completion is still not working in Sublime Text 2

I did the following:

composer update
Loading composer repositories with package information
Updating dependencies (including require-dev)

  • Installing dannykopping/docblock (dev-master 8ae1dc5)
    Downloading: 100%
  • Installing barryvdh/laravel-ide-helper (dev-master 3d2934b)
    Downloading: 100%

Writing lock file
Generating autoload files
Generating optimized class loader...
Compiling common classes...

./artisan ide-helper:generate -S
A new helper file was written to _IDE_helper.php

Restarted Sublime and still nothing. Any ideas?

Class 'Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider' not found

Hi. I've tried to find my mistake, but I can't. I've been following the "Automatic phpDoc generation for Laravel Facades" guide, but i fails.

Running MAMP PRO with php 5.4.10.

After adding 'Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider', to the app/config/app.php this error is appearing:

Symfony \ Component \ Debug \ Exception \ FatalErrorException
Class 'Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider' not found in
/Users/x/Sites/laravel/todo/vendor/laravel/framework/src/Illuminate/Foundation/ProviderRepository.php line 158

If I run the `php artisan ide-helper:generate`` it generates this error

`PHP Fatal error: Class 'Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider' not found in /Users/michaelsoerensen/Sites/laravel/todo/vendor/laravel/framework/src/Illuminate/Foundation/ProviderRepository.php on line 158
{"error":{"type":"Symfony\Component\Debug\Exception\FatalErrorException","message":"Class 'Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider' not found","file":"/Users/michaelsoerensen/Sites/laravel/todo/vendor/laravel/framework/src/Illuminate/Foundation/ProviderRepository.php","line":158}}{"error":{"type":"Symfony\Component\Debug\Excep [something more I can't see....)``

The php error log have this:
PHP Fatal error: Class 'Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider' not found in /Users/michaelsoerensen/Sites/laravel/todo/vendor/laravel/framework/src/Illuminate/Foundation/ProviderRepository.php on line 158

Any help is much much appreciated

Thanks :-)

PHPDoc not generated for models

First, let me say this is a fantastic tool. Thank you :)

I understand this is still in beta, but didn't see an issue for it so I thought I'd create one. I'm using "laravel/framework": "4.1.*" with "barryvdh/laravel-ide-helper": "1.*".

This class's database table exists in my default database connection. When running php artisan ide-helper:models it only generated the @property-read documentation and did not recognize the database columns.

namespace Models\Broadcasts\Voice;

use Illuminate\Database\Eloquent\Model as Eloquent;

/**
 * My class description
 *
 * @property-read \Models\Broadcasts\Voice\VoiceBroadcast $voiceBroadcast
 */
class VoiceCall extends Eloquent
{

    /**
     * Guarded attrs
     *
     * @var array
     */
    protected $guarded = [];

    /**
     * Validation rules for class
     *
     * @var array
     */
    public static $rules = [
        'to' => 'required',
        'voice_broadcast_id' => 'required'
    ];


    /**
     * Relationship with parent voice broadcast
     *
     * @return Models\Broadcasts\Voice\VoiceBroadcast
     */
    public function voiceBroadcast()
    {
        return $this->belongsTo('Models\Broadcasts\Voice\VoiceBroadcast');
    }
}

Issue with the "Helpers" option.

Hello,

I just discovered an issue when I use the option "Helpers" (helpers => true) in the config.
Composer throw an exception because there is no option "nohelpers".

Seam that this issue is caused by this code: " && ! $this->option('nohelpers') ";
removing this code make your helper working perfectly !

Ho, a little thing, thank's for this useful helper (and sorry for my so French English...) !

[Request] automatic documentation of dynamic whereField functions on models

Laravel has a cool feature, you can use

User::whereFieldName($value)->get() to get the models.

Since the ide-helper is already scanning the tables it knows that fields there are, can we please have the documentation generate the documentation as below

@method \Illuminate\Database\Query\Builder|static whereField()  whereField($value)  search by Field
@method \Illuminate\Database\Query\Builder|static whereField2() whereField2($value) search by Field2

It's actually a lot more powerful, for example using

User::whereUsernameAndEmailOrResetToken([$username, $email, $resetToken])

Is perfectly valid but trying to document them all is not feasible, so I vote for only doing the single column dynamic Where's

Artisan:call() method missing.

Artisan::call() is used to call artisan commands from your app. this function is missing from the helper generated output.

Workbench models

It would be nice if it could generate the model properties for models contained within workbench packages :) Possibly through giving it an optional dir parameter to set the directory loadModels uses, defaulting to app_path().'/models' when the parameter is not set.

Not working without reason

It's not working for me. Only Artisan, Config, Controller, Eloquent, File, Form, Paginator, Queue, View autocompleting to name without namespace.

Laravel: 4.0.7
PhpStorm: 6.0.3

Auth::extend missing

So it's apparently possible to call Auth::extend. I think it comes from Auth extending Manager. The IDE helper doesn't seem to have this in it, though.

Request: Pass wildcard characters when generating model docs

Hi Barry,

This is a request for a good to have feature, not sure how easy or difficult this is to implement. Is it possible to have wildcard characters when generating model docs

For example:

php artisan ide-helper:models User*

which will look for all the Models that starts with User and generate the docs for all of them

or

php artisan ide-helper:models %User

which will look for all the Models ending with User and generate the docs for all of them

or

php artisan ide-helper:models %User%

which will look for all the Models containing the characters User and generate the docs for all of them

Since a day it doesn't work

The automatic generator creates a file with all the methods but without the @param / @return properties...

I've included in the composer.json:

{
    "require": {
        "laravel/framework": "4.0.*",
        "barryvdh/laravel-ide-helper": "1.*"
    },
    "autoload": {
        "classmap": [
            "app/commands",
            "app/controllers",
            "app/models",
            "app/database/migrations",
            "app/database/seeds",
            "app/tests/TestCase.php"
        ]
    },
    "scripts": {
        "pre-update-cmd": [
            "php artisan clear-compiled"
        ],
        "post-install-cmd": [
            "php artisan optimize"
        ],
        "post-update-cmd": [
            "php artisan optimize",
            "php artisan ide-helper:generate"
        ]
    },
    "config": {
        "preferred-install": "dist"
    },
    "minimum-stability": "dev"
}

Suggestions?

RuntimeException when installing

composer require barryvdh/laravel-ide-helper:1.*

./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)

  • Installing doctrine/lexer (v1.0)
    Downloading: 100%
  • Installing doctrine/annotations (v1.1.2)
    Downloading: 100%
  • Installing doctrine/collections (v1.1)
    Downloading: 100%
  • Installing doctrine/cache (v1.3.0)
    Downloading: 100%
  • Installing doctrine/inflector (v1.0)
    Downloading: 100%
  • Installing doctrine/common (v2.4.1)
    Downloading: 100%
  • Installing doctrine/dbal (v2.4.2)
    Downloading: 100%
  • Installing symfony/class-loader (v2.4.1)
    Downloading: 100%
  • Installing dflydev/markdown (v1.0.3)
    Downloading: 100%
  • Installing phpdocumentor/reflection-docblock (2.0.0)
    Downloading: 100%
  • Installing barryvdh/laravel-ide-helper (v1.8.0)
    Downloading: 100%

Writing lock file
Generating autoload files
Mcrypt PHP extension required.
Script php artisan clear-compiled handling the post-update-cmd event returned with an error

[RuntimeException]
Error Output:

require [--dev] [--prefer-source] [--prefer-dist] [--no-progress] [--no-update] [packages1] ... [packagesN]

How to set Doctrine custom mapping types

Hello! I'm trying your helpers and I find them very useful, anyway I'm stuck trying to use your models docs generator.

The script return this error:

Exception: Unknown database type enum requested, Doctrine\DBAL\Platforms\MySqlPlatform may not support it.

Searching on google I found the solution to this problem is to map the unknown type to a safe one, like string, here in the doctrine's doc

So I tried to add that parameter to my database config array but it's not working:

'connections' => array(

    'mysql' => array(
        'driver'    => 'mysql',
        'host'      => 'localhost',
                    ...
        'mapping_types' => array(
            'enum' => 'string'
        ),
    ),

So is this a Laravel4 related problem? Or I'm just doing it wrong?

Custom interface problem

Hi there!

I've got my own interface, which is added in class aliases in /app/config/app.php:

'SomeInterface' => 'My\Own\SomeInterface',

And laravel-ide-helper generates _ide_helper.php:

class SomeInterface{
}

But expected:

interface SomeInterface extends My\Own\SomeInterface{
}

Thanks!

Package doesn't seem to take into consideration the current environment of artisan

When running php artisan ide-helper:generate or php artisan ide-helper:models it doesn't seem to take into consideration the current envrionment's configuration. It is required to explicity specify the --env configuration when the command is used.

It keeps throwing the error

Exception: SQLSTATE[HY000] [2002] A connection attempt failed because the connected party did 
not properly respond after a period of time, or established connection failed because connected 
host has failed to respond.

if --env is not specified.

Allow additional model locations

Our models are namespaced.

So our App looks like this

/app
/app/models/User.php
/app/modules/ShortCourses/Models/Course.php

So it would be useful to be able to specify an additional array of directories to look in for models.

On the upside, for models in the /app/models directory it maps perfectly for namespaced models :D

Getting an error when running artisan command

php artisan ide-helper:generate -S

returns the following error:

"error":{"type":"Symfony\Component\Debug\Exception\FatalErrorException","message":"Class 'Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider' not found","file":"/www/site/bootstrap/compiled.php","line":7075}}

@inheritdoc specific problem

Hi there!

Steps to reproduce:

class A
{
}

class B extends A
{

    /**
     * {@inheritdoc}
     */
    public function iAmNotExistInMyParent()
    {
        // but I do have @inheritdoc
    }

}

Expected:

Correct _ide_helper.php would be generated.

Results:

Exception: Method iAmNotExistInMyParent does not exist
Could not analyze Path\To\The\Class\Here.

PS:

Looks like that problem is specific for php 5.4, and behaviour on php 5.5 is normal.

Problem occurs in protected function getInheritDoc($reflectionMethod){, I guess.
Looks like we need additional check there.

Thank you!

[bug] Exception when Running ide-helper:generate

vagrant@precise64:/vagrant$ rm -rf composer.lock vendor/
vagrant@precise64:/vagrant$ composer install --dev
vagrant@precise64:/vagrant$ php artisan ide-helper:generate
{
    "error": {
        "type":"ErrorException",
        "message":"Missing argument 1 for Illuminate\\Auth\\AuthManager::createDriver(), called in \/vagrant\/vendor\/laravel\/framework\/src\/Illuminate\/Support\/Manager.php on line 79 and defined",
        "file":"\/vagrant\/vendor\/laravel\/framework\/src\/Illuminate\/Auth\/AuthManager.php",
        "line":13
    }
}

Here are the relevant parts of my composer.json

"require": {
    "laravel/framework": "4.0.*",
        "dflydev/markdown": "1.0.*@dev",
        "rhumsaa/uuid": "~2.3",
        "mews/useragent": "dev-master",
        "aws/aws-sdk-php-laravel": "dev-master"
},
"require-dev": {
        "mockery/mockery": "dev-master",
        "sami/sami": "1.0.*@dev",
        "way/laravel-test-helpers": "dev-master",
        "barryvdh/laravel-ide-helper": "1.*"
},

I have included the service provider in app/config/app.php as instructed:

'Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider',

[Request] Support overriding methods

I want to be able to specify what model in particular something like Auth::user() returns, to do this I was hoping I could just add a couple of lines to the config file:

'Auth' => array(
    'user' => 'User::__construct'
)

This kind of works, in that the method is generated successfully, however this means we now have two user methods in the helper under auth instead of just the more explicit one.

Request: Ability to ignore models when generating php docs for models

Can a configuration be provided using which some models can be ignored when generating php docs for the models.

My use case is the following:
My application has few models communicating to MongoDB and some to MySQL.
When ide-helper generates the phpdocs, it throws and error

Exception: call_user_func_array() expects parameter 1 to be a valid callback, class 'MongoDB' does not have a method 'getDoctrineDriver'
Could not analyze class Action.

So this just errors out and does not generate the PHP docs.

So if there was a configuration, something like

php artisan ide-helper:models ignore-models:Model1,Model2

we could ignore the required models.

Possibly a typo in ModelsCommand.php

I think that there is a typo on line 245 in ModelsCommand.php file.

if(\Str::startsWith($method, 'get') && \Str::endsWith($method, 'Attribute') && $method !== 'setAttribute'){
                   //Magic get<name>Attribute

Final check in if statement is "$method !== 'setAttribute')" and judging by the rest of checks it should be "$method !== 'getAttribute')" (for getters)

Validator extends wrong class

class Validator should extend Illuminate\Validation\Validator not Illuminate\Validation\Factory

to test (in phpstorm):

$validate = Validator::make($rules);
$validate->passes();

when it extends the factory class passes() is not found

[QUERY] Autocomplete and syntax highlighter in blades

Hi,

Im new to laravel and this type of development environment in general. I have installed this extension for phpStorm and have the auto completion working (so thanks on that!).

My question is, how can I get the to auto completion working in blades using the laravel template syntax?

If i break into php, it works - but using the {{ }} brackets for the templating stuff - it dosnt!

Any ideas?! Also styling the syntax, is that possible?!

:models cannot understand nested conditions

In our models our relationships are conditioned:

$relation = $this->hasMany(...);
return $this->restrict ? $this->restrict($relation) : $relation;

however the ide-helper looks for a literal return $this-> and takes the rest as the relationship, this is an issue since the relation is defined on the previous line.

I suggest updating the code so it looks for $this->[relationshipName] e.g. Look for $this->hasMany and parse that line instead.

This would allow the relationship to be parsed out no matter what the method looks like.

Newbie: 'IdeHelperServiceProvider not found'

I eventually got this working, with the easy bootstrap I recommend, at
https://github.com/andrew13/Laravel-4-Bootstrap-Starter-Site
Note that this project requires php v5.4+

tldr;
Hopefully, fixing this, won't break dependent projects, like the one above.
Instructions for directories should be more specific, as there are multiple "laravel" directories and composer.json files. The bootstrap above installs to vendor/barryvdh/laravel-ide-helper/ rather than vendor/laravel-ide-helper/ as instructed, for starters. I also tried that directory, amongst several others, but still got the error below.
Note that composer update works, until I make the change to app.php, as directed by readme.md
This is a new project, with git clones for June 6, 2013
Thanks for your efforts!

~/site> composer update

PHP Fatal error: Class 'Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider' not found in /home/bruce/public_html/site/vendor/laravel/framework/src/Illuminate/Foundation/ProviderRepository.php on line 123
PHP Stack trace:
PHP 1. {main}() /home/bruce/public_html/site/artisan:0
PHP 2. require_once() /home/bruce/public_html/site/artisan:30
PHP 3. require() /home/bruce/public_html/site/bootstrap/start.php:61
PHP 4. Illuminate\Foundation\ProviderRepository->load() /home/bruce/public_html/site/vendor/laravel/framework/src/Illuminate/Foundation/start.php:195
PHP 5. Illuminate\Foundation\ProviderRepository->compileManifest() /home/bruce/public_html/site/vendor/laravel/framework/src/Illuminate/Foundation/ProviderRepository.php:51
PHP 6. Illuminate\Foundation\ProviderRepository->createProvider() /home/bruce/public_html/site/vendor/laravel/framework/src/Illuminate/Foundation/ProviderRepository.php:89
{"error":{"type":"Symfony\Component\Debug\Exception\FatalErrorException","message":"Class 'Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider' not found","file":"/home/bruce/public_html/site/vendor/laravel/framework/src/Illuminate/Foundation/ProviderRepository.php","line":123}}Script php artisan clear-compiled handling the pre-update-cmd event returned with an error

[RuntimeException]
Error Output: PHP Fatal error: Class 'Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider' not found in /home/bruce/public_html/site/vend
or/laravel/framework/src/Illuminate/Foundation/ProviderRepository.php on line 123
PHP Stack trace:
PHP 1. {main}() /home/bruce/public_html/site/artisan:0
PHP 2. require_once() /home/bruce/public_html/site/artisan:30
PHP 3. require() /home/bruce/public_html/site/bootstrap/start.php:61
PHP 4. Illuminate\Foundation\ProviderRepository->load() /home/bruce/public_html/site/vendor/laravel/framework/src/Illuminate/Foundation
/start.php:195
PHP 5. Illuminate\Foundation\ProviderRepository->compileManifest() /home/bruce/public_html/site/vendor/laravel/framework/src/Illuminate
/Foundation/ProviderRepository.php:51
PHP 6. Illuminate\Foundation\ProviderRepository->createProvider() /home/bruce/public_html/site/vendor/laravel/framework/src/Illuminate/
Foundation/ProviderRepository.php:89

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.