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

I am looking for sth similiar to Intellisense in .NET in Laravel. So far I've been using .NET and autocompletion for models is awesome and makes my work way more easy.

Now I need to create Laravel application, I've been following this tutorial to prepare my environment but the only autocompletion I get is for default PHP functions and some predefined methods (ex. SaveSessionListener from Symfony\Component\HttpKernel\EventListener - I am not even using Symfony anywhere).

What I'd like to achieve is get autocompletion from models, for example there is a class called Model in Laravel, I have class Page which extends Model.

use App/Page

$home = new Page();
$home->content = "lorem ipsum";
$home->save();

I don't have any completion when I write $home->, no content, no save(), only some random functions. I can understand why there might be no content autocompletion - its not written directly into code, but its written on database and object-database engine is parsing that one, I didn't figure out how yet, but I don't understand why even save() doesn't get autocompletion.

I tried to google the issue, but without any good result.



Solution 1:[1]

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');
  }
}

Solution 2:[2]

Update:

You can now use Laravel Extra Intellisense is now supporting Model Attributes.

Still in Beta but it works fine.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Eduardo Cuomo
Solution 2 Goper Leo Zosa