laravel-idea / plugin

Laravel Idea plugin for PhpStorm
https://laravel-idea.com/
166 stars 7 forks source link

[Bug]: Route naming not working on autocomplete #948

Open mariosvasiliou opened 6 months ago

mariosvasiliou commented 6 months ago

Bug description

If you specify a name prefix in RouteService Provider, autocomplete does not work correctly and cannot find a route name.

Plugin version

8.1.2.233

Operating system

Windows

Steps to reproduce

Add to RouteServiceProvider Route::prefix('api/v2') ->middleware(['api_v2']) ->as('api.v2.') ->group(base_path('routes/api/v2.php')); In the v2 file add Route::prefix('admin') ->as('admin.') ->group(function(): void { Route::apiResource('logs', SystemLogsController::class); });

Try to find the route name using route() function. You are expecting to find api.v2.admin.logs.index for example but it finds admin.logs.index

Relevant log output

No response

adelf commented 6 months ago

Thank you for posting this. I still can't believe this mistake was made. Fixed. The new update will be released next week.

adelf commented 4 months ago

Fixed in 8.1.4

mariosvasiliou commented 4 months ago

Hello @adelf
It seems that the problem still exists and not fixed 🤔

adelf commented 4 months ago

Hmmm...

image

Could you check your plugin version? If it's 8.1.4 and still doesn't work, could you send me your files(provider and route)?

mariosvasiliou commented 4 months ago

Hello @adelf . thank you for your reply. I have the latest version 8.1.4.241. I cannot send all the files since I am working in a company and there are thousands of routes but I can send you some parts. In RouteServiceProvider I have this

  Route::prefix('api/v2')
             ->middleware(['api_v2'])
             ->as('api.v2.')
             ->group(base_path('routes/api/v2.php'));

In the v2 route file, I have this line

....
require __DIR__.'/v2/auth_mfa_password.php';
.....

In auth_mfa_password file I have this

Route::middleware(['auth.api.v2', 'mfa', 'password_expired', 'verified', 'throttle:api'])
     ->group(function () {
         require __DIR__.'/sections/admin.php';
      .....
     });

In the admin route php file I have this

Route::prefix('admin')
     ->as('admin.')
     ->group(function (): void {
         Route::prefix('corporate')->name('corporate.')->group(function () {
             Route::apiResource('company-groups', CompanyGroupController::class);
             ........            

When I am typing in route() helper none of the v2 route names appear... and I have hundreds of routes. Also if I type it manually it doesn't link like other routes. I have a similar structure for routes in web and API v1 and those are working fine. All my coworkers have same issue.

adelf commented 4 months ago

Got it now. Laravel Idea doesn't run PHP, so I have to parse all route files manually. I think the problem is in simple require call. I'll try to fix this. Thank you.

mariosvasiliou commented 4 months ago

I don't think require is the problem because for web I have something like this for web routes. In RouteServiceProvider

 Route::middleware('web')
             ->group(\base_path('routes/web.php'));

In the web route file

...
require __DIR__.'/web/auth_mfa_password.php';
...

In auth_mfa_password route file

Route::middleware(['auth:web', 'mfa', 'password_expired'])->group(function (): void {
    require __DIR__.'/sections/zygos_hub.php';

This works just fine. If I add something like this in the Service Provider it will not work.

    Route::middleware('web')
            ->as('web.')
             ->group(\base_path('routes/web.php'));

image image

I believe the issue is when combined as() in route names on Service Provider with required file in route files. If that helps.

adelf commented 1 month ago

Could you check it in the new Laravel Idea 8.2?

mariosvasiliou commented 1 month ago

Unfortunately the problem still exists :(

Could you check it in the new Laravel Idea 8.2?