Poma Poma - 8 months ago 151
PHP Question

How to enable autocomplete for Laravel Resources in PhpStorm?

Laravel 5.5 has a new API Resources feature, and it nicely redirects calls to model attributes (like

). I use
to generate phpdocs for models that type-hints all model attributes. However, this does not apply to a resource and I get "Field accessed via magic method" squigglies. Is there a way to point it to model's phpdoc without copying it?

Answer Source

You can use the @mixin

Here is an example, If you want the properties/phpdocs from the User model in your User Resource, then do like this

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,
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download