idea-php-laravel-plugin icon indicating copy to clipboard operation
idea-php-laravel-plugin copied to clipboard

Does not find partial namespaced controllers

Open webmake opened this issue 8 years ago • 5 comments

Hi, using laravel modules via bundle or defining custom controllers (not in \\App\\Http\\Controllers\\ path) doesn't work neither autocomplete, neither navigation (when defining namespace and after that controller). It still autocompletes with fully namespaced controller:

Expected:
Route::group(['middleware' => 'web', 'prefix' => 'cool', 'namespace' => 'Modules\Dummy\Http\Controllers'], function()
{
    Route::get('/', 'DummyController@index');
});

Works navigation only with this, but wrongly, because actual controller Class Modules\Cool\Http\Controllers\Modules\Cool\Http\Controllers\CoolController does not exist:
Route::group(['middleware' => 'web', 'prefix' => 'cool', 'namespace' => 'Modules\Dummy\Http\Controllers'], function()
{
    Route::get('/', 'Modules\Dummy\Http\Controllers\DummyController@index');
});

I see it is hardcoded now https://github.com/Haehnchen/idea-php-laravel-plugin/blob/93285fad392c7fe221eafb2b482cd7d6b15ee3c9/src/de/espend/idea/laravel/controller/ControllerCollector.java#L28

Wouldn't it be possible at least add controllers manually in phpstorm plugin configs? Or maybe there is way bypass this?

webmake avatar Jan 08 '17 21:01 webmake

@webmake it searches all subclasses from \Illuminate\Routing\Controller class, base laravel class for controllers. Why your bundle controllers isn't inherited from it? Do they have any common parent?

adelf avatar Jan 09 '17 12:01 adelf

Oh sorry for desinformation a little bit,

Yes, I am extending that abstract class, and tested that works good if in group is defined namespace, but I simplified problem wrongly.

I forgot to mention that my case is that I use my own RouteServiceProvider

<?php

namespace Modules\Dummy\Providers;

use Illuminate\Routing\Router;

class RouteServiceProvider extends \Illuminate\Foundation\Support\Providers\RouteServiceProvider
{
    protected $namespace = 'Modules\Dummy\Http\Controllers';

    public function map(Router $router)
    {
        $this->mapWebRoutes($router);
    }

    protected function mapWebRoutes(Router $router)
    {
        $router->group([
            'namespace' => $this->namespace,
            'middleware' => 'web',
        ], function () {
            require __DIR__ . '/../Http/routes.php';
        });
    }
}

My controller

<?php

namespace Modules\Dummy\Http\Controllers;

class DummyController extends \Illuminate\Routing\Controller
{
    /**
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
     */
    public function index()
    {
        return view('index');
    }
}

So namespace in route provider is invisible for routes.php file. autocomplete

webmake avatar Jan 09 '17 13:01 webmake

Do you have another RouteServiceProvider in this project?

adelf avatar Jan 09 '17 13:01 adelf

Yes, multiple, as much as modules are I guess, plus laravel installer generated default provider (app/Providers/RouteServiceProvider.php)

webmake avatar Jan 09 '17 13:01 webmake

Ok, thanks. Multiple default controllers namespaces. It can be fixed, I think. I'll try to do it a bit later.

adelf avatar Jan 09 '17 13:01 adelf