PHPDoc generation for Eloquent API Resources

2
open
william-lohan
william-lohan
Posted 2 months ago

PHPDoc generation for Eloquent API Resources #1246

Summary

In the following code:

<?php

namespace App\Http\Resources;

use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;

class MyModelResource extends JsonResource
{
    /**
     * Transform the resource into an array.
     *
     * @param Request  $request
     * @return array
     */
    public function toArray($request)
    {
        return [
            'name' => $this->name
        ];
    }
}

"name" has a warning (green squiggly) for "Property accessed via magic method". Could there be a way to generate a PHPDoc like php artisan ide-helper:models does to give MyModelResource a @property string name some where?

See

Note that we can access model properties directly from the $this variable. This is because a resource class will automatically proxy property and method access down to the underlying model for convenient access. Once the resource is defined, it may be returned from a route or controller. The resource accepts the underlying model instance via its constructor: - https://laravel.com/docs/8.x/eloquent-resources#concept-overview

rizkyarlin
rizkyarlin
Created 1 month ago

this will be great!

PaulMenheere
PaulMenheere
Created 2 days ago

if you would use @mixin it will work