laravel-ide-helper icon indicating copy to clipboard operation
laravel-ide-helper copied to clipboard

Macro on JsonResource not detected

Open patrick-radius opened this issue 3 years ago • 2 comments

Versions:

  • ide-helper Version: 2.12.3
  • Laravel Version: 9.23.0
  • PHP Version: 8.1

Description:

When adding a macro on a JsonResource (which gets Macroable via the trait DelegatesToResource) it is not picked up by the ide-helper. When adding the exact same macro to the Str class (as a test to see if the macro definition itself is faulty) it is picked up.

Steps To Reproduce:

Add a macro in the AppServiceProvider boot method:

JsonResource::macro('wantsRelation', function(string $relation_name, mixed $value, mixed $default = null): mixed {
...
})

No macro is detected.

Add same macro on the Str class:

Str::macro('wantsRelation', function(string $relation_name, mixed $value, mixed $default = null): mixed {
...
})

and the macro is detected.

patrick-radius avatar Aug 08 '22 15:08 patrick-radius

Same problem with Carbon macros

Muetze42 avatar Mar 29 '24 21:03 Muetze42

@Muetze42 I've just started to notice I'm having the same issue. No Carbon Macos are being picked up.

Investigating!

Edit:

Ugh I had forgot I had chased up on this years ago!!!

https://github.com/barryvdh/laravel-ide-helper/issues/1162

Sort of solution: https://github.com/barryvdh/laravel-ide-helper/issues/40

I have a file I created .phpstorm.meta.php/custom_ide_auto_complete_helper.php And in it I just put all my custom Carbon macros like as follows and it now autocompletes.

<?php
namespace Illuminate\Support {

    use Carbon\CarbonImmutable;
    use Carbon\CarbonInterface;

    /**
     * @method static CarbonInterface minsToHours($minutes) Convert a number of minutes into hh:mm with no days.
     * <ADD MORE HERE>
     */
    class Carbon
    {
    }
}



jonnywilliamson avatar Apr 14 '24 13:04 jonnywilliamson