How to enable autocomplete Laravel resources in PhpStorm?

Laravel 5.5 has a new API Resources function and perfectly redirects calls to model attributes (for example, $this->id). I use ide-helper:modelsphpdocs to generate models that are typing - all the attributes of the model. However, this does not apply to the resource, and I get squigglies "Access the field through the magic method". Is there any way to point it to the phpdoc model without copying it?

+4
source share
1 answer

You can use @mixin

Here is an example. If you want the / phpdocs properties from the User model in your user resource, follow these steps:

namespace App\Http\Resources;

use Illuminate\Http\Resources\Json\Resource;

/**
 * Class User
 *
 * @mixin \User
 * */
class User extends Resource
{
    public function toArray($request)
    {
        return [
            'id' => $this->id,
            'name' => $this->name,
            'email' => $this->email,
            'created_at' => $this->created_at,
            'updated_at' => $this->updated_at,
        ];
    }
}
+4
source

Source: https://habr.com/ru/post/1686755/


All Articles