Route names completion doesn't list all routes
I have the following structure:
routes/web.php
foreach (File::allFiles(__DIR__.'/web') as $file) {
require $file->getPathname();
}
And some routing files separated per module:
routes/web/moduleA.php
routes/web/moduleB.php
...
Some module files have multiple Route::group() defined.
Before I open those files I don't have route names completion, after I opened them once it shows me the routes.
Somehow this wasn't an issue this plugin Are there any known issues if I run both plugins together?
Are there any known issues if I run both plugins together?
There are no compatibility issues with the old plugin.
Laravel Idea tries to find the information about each route file. For example if RouteServiceProvider contains:
Route::prefix('api')
->as('api.')
->middleware('api')
->namespace($this->namespace)
->group(base_path('routes/api.php'));
Plugin will know that route names in the api.php file has "api." prefix. However, it doesn't work for dynamic
foreach (File::allFiles(__DIR__.'/web') as $file) {
require $file->getPathname();
}
So, for this case, the simple way as used in the old Laravel plugin(just use empty prefix) is better :) There is a workaround by adding phpDocs to the beginning of the route files:
/**
* @routePrefix("api.")
* @routeNamespace("App\Http\Controllers")
*/
But it's a bit ugly. I'll try to find a better solution. At least I can add an option: "smart" or "simple" route files processing.
Hey, Adrian. Why? I was going to support this kind of route registration by description in the ide.json file
@adelf was going through my open issues and found this one. I don't face that issue anymore. So I thought I can close it😉
Ok. This issue is mine now! )
FYI I still need to add the comment to support this on my code. @adelf
/**
* PhpStorm Laravel-idea plugin helper comment
* @routePrefix("admin")
* @routeNamespace("App\Http\Controllers")
*/
Route::prefix('admin')
->namespace('Admin')
->middleware(['auth', 'enabled', 'admin'])
->group(function () {
Route::match(['get', 'post'], 'profile', 'HomeController@profile')
->name('admin-profile');
});
@delmicio how do you register the admin.php file in the RouteServiceProvider?
RouteServiceProvider
It is not the default Laravel 5.5 setup. We need a custom logic to better organize routes.
public function map()
{
$this->mapWebRoutes();
}
/**
* Define the "web" routes for the application.
*
* These routes all receive session state, CSRF protection, etc.
*
* @return void
*/
protected function mapWebRoutes()
{
Route::middleware('web')
->namespace($this->namespace)
->group(function () {
$this->requireRoutes('routes/web');
});
}
/**
* @param $path
*
* @return Collection
*/
public function requireRoutes($path)
{
return collect(
Finder::create()
->in(base_path($path))
->name('*.php')
)->each(function ($file) {
/** @var SplFileInfo $file */
include_once $file->getRealPath();
});
}
