Intellisense (autocompletion) for model in Laravel for Visual Studio Code or another IDE

I figured it out how to get it work with Visual Studio Code.

First and most important is the link morph provided me in comment: laravel-ide-helper

I just followed docs and generated basic helper + model helper. I guess later I'll automate those generation commands, its also explained how to do it in docs.

Second thing is that it works only with: PHP Intelephense plugin Note that you need to reset VSC before it actually works.

Third thing I did - VSC have build-in php autocompletion, it was pretty annoying cause it started to show me model fields in suggestions, but it was between dozens of other suggestions. To disable build-in autocompletion I added line to user settings:

"php.suggest.basic": false,

Last thing I did - I have moved snippets to bottom of suggestions box to clear autocompletion results a little bit more:

"editor.snippetSuggestions": "bottom"

And that works really decent as Laravel programming environment.


I use PHP Doc for fields definition like following example:

namespace App\Models;

use App\Enums\MediaType;
use App\Models\Commons\BaseModel;
use DateTime;

/**
 * Famous Media.
 *
 * @property int $id
 * @property int $famous_id
 * @property MediaType $type
 * @property string $url
 * @property int $position
 * @property DateTime $created_at
 * @property DateTime $updated_at
 */
class FamousMedia extends BaseModel
{
  const TABLE = 'famous_medias';

  /**
   * The attributes that are mass assignable.
   *
   * @var array
   */
  protected $fillable = [
    'type',
    'url',
    'position',
    'famous_id',
  ];

  /**
   * The attributes that should be hidden for arrays.
   *
   * @var array
   */
  protected $hidden = [
    'famous_id',
    'deleted_at',
    'created_at',
    'updated_at',
  ];

  public function famous()
  {
    return $this->hasOne(Famous::class, 'famous_id');
  }
}