QA: PhpStorm doesn’t recognize Eloquent methods

Well well well, look who is having the most irritating problem when working with Laravel and PhpStorm 🙋‍♂️.

You may have tried laravel-ide-helper, let’s be honest here, who wants to have their projects flooded with code that does not add real value for the user but only for developer?

The answer: not me 😤

Problem:

You may see in your PhpStorm project similar errors, when using eloquent methods, like for example ::updateOrCreate() or ::create().

Solution:

Is called php docblock. Take a look at the code below. There is a bit of doc block annotating the eloquent class with properties and also with @mixing declaration.

This declaration will simply make your method clickable and by doing so you will know, if you may have made a mistake or a typo.

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Builder;

/**
 * @property int $id
 * @property string $name
 *
 * @mixin Builder
 */
class JiraCloudInstanceProject extends Model {

}

A word of caution here, be sure to use a Builder class from the namespace Illuminate\Database\Eloquent\Builder because otherwise it will not work.

Wrapping up:

In this article I showed you how to solve the most irritating problem when coding with Laravel and PhpStorm.

Hope this helps.

Yours in coding,

Until next time

Ivan

Sources:

Leave a comment

Your email address will not be published. Required fields are marked *