Using namespaces in Laravel Routes

Answered

Hi all,

I'm using PHP storm to code some Laravel applications and I like to order controllers into folders to have everything separeated. When I try to add a new route, to avoid adding the full path to each of the Controller calls, I use the namespace function which automatically searches within the given path.

The question is, is there any way to make PHPStorm take in account namespaces ? Each time I try to call a controller PHPStorms recognices the full path but doesn't take in account namespaces.


Regards!

0
3 comments

Hi there,

Examples/screenshots please.

 

But in any case: Laravel-specific functionality is provided by 3rd party Laravel plugin.

If I'm getting you correctly -- you are talking about "Admin\Auth\LoginController@showLoginForm" completion in this sample code:

    Route::get('login', 'Admin\Auth\LoginController@showLoginForm')->name('admin.auth.login');

Such completion is provided by Laravel plugin. Have a look at these links then:

0
Avatar
Permanently deleted user

Thanks for your  comment, here an example:

 

I have a controller called EventController within the path app/Http/Controllers/Events/EventController.php

If I set the namespace 'Events' to make it clearer I ahve to specify the functions as follow:

 

Route::namespace('Events')->prefix('events')->name('events::')->group(function () {

Route::get('/', [
'as' => 'all',
'uses' => 'EventController@all',
]);

Route::get('search', [
'as' => 'search',
'uses' => 'EventController@search',
]);

});

 

If instead of EventController@search I use Events/EventController@search (and of course remove namespace statement) is recognizedand I can navigate from my routes to my controller with Ctrl+Click but once I set the namespace is not possible, is there any way to enable namespacing in routes?

0

Check the links -- such completion/navigation is provided by 3rd partty Laravel plugin.

2

Please sign in to leave a comment.