Zend Service Manager - Service not found exception when trying to use phpdebugbar - mezzio

I'm trying to use https://github.com/php-middleware/phpdebugbar in a clean Zend Expressive Skeleton application.
I know the instructions on this page suggest using this DI configuration (if using pimple):
$container[Psr\Http\Message\ResponseInterface::class] = new Zend\Diactoros\ResponseFactory();
$container[Psr\Http\Message\StreamFactoryInterface] = new Zend\Diactoros\StreamFactory();
So I tried using this (I'm using zend service manager):
return [
'dependencies' => [
'factories' => [
Psr\Http\Message\ResponseInterface::class => new Zend\Diactoros\ResponseFactory(),
'Psr\Http\Message\StreamFactoryInterface' => new Zend\Diactoros\StreamFactory(),
],
],
];
But I'm running into the following error:
PHP Fatal error: Uncaught Zend\ServiceManager\Exception\ServiceNotFoundException: Unable to resolve service "Psr\Http\Message\ResponseInterface" to a factory; are you certain you provided it during configuration? in /www/develop.expressive.centralsemi.com/htdocs/vendor/zendframework/zend-servicemanager/src/ServiceManager.php:687
I also tried this:
return [
'dependencies' => [
'factories' => [
Psr\Http\Message\ResponseInterface::class => new Zend\Diactoros\ResponseFactory(),
Psr\Http\Message\StreamFactoryInterface::class => new Zend\Diactoros\StreamFactory(),
],
],
];
and this:
return [
'dependencies' => [
'factories' => [
Psr\Http\Message\ResponseInterface::class => Zend\Diactoros\ResponseFactory::class,
Psr\Http\Message\StreamFactoryInterface::class => Zend\Diactoros\StreamFactory::class,
],
],
];
But still no luck.
Admittedly, I'm not familiar with Zend/Diactoros, but I don't understand how Zend\Diactoros\ResponseFactory can be a factory, it doesn't have an __invoke() method. So I feel like that is the core of my issue. Am I supposed to create my own factory for this? I feel like that is not the intended way to do this.
Note, I've also tried following these instructions. And while there is no error, it doesn't seem like it's showing up at all:
https://docs.zendframework.com/zend-expressive/v3/cookbook/debug-toolbars/
I'm sure I'm missing some key part, but what is it that I'm missing?
My composer.json:
{
"name": "zendframework/zend-expressive-skeleton",
"description": "Zend expressive skeleton. Begin developing PSR-15 middleware applications in seconds!",
"type": "project",
"homepage": "https://github.com/zendframework/zend-expressive-skeleton",
"license": "BSD-3-Clause",
"keywords": [
"skeleton",
"middleware",
"psr",
"psr-7",
"psr-11",
"psr-15",
"zf",
"zendframework",
"zend-expressive"
],
"config": {
"sort-packages": true
},
"extra": {
"zf": {
"component-whitelist": [
"zendframework/zend-expressive",
"zendframework/zend-expressive-helpers",
"zendframework/zend-expressive-router",
"zendframework/zend-httphandlerrunner",
"zendframework/zend-expressive-fastroute",
"zendframework/zend-expressive-twigrenderer"
]
}
},
"support": {
"issues": "https://github.com/zendframework/zend-expressive-skeleton/issues",
"source": "https://github.com/zendframework/zend-expressive-skeleton",
"rss": "https://github.com/zendframework/zend-expressive-skeleton/releases.atom",
"slack": "https://zendframework-slack.herokuapp.com",
"forum": "https://discourse.zendframework.com/c/questions/expressive"
},
"require": {
"php": "^7.1",
"zendframework/zend-component-installer": "^2.1.1",
"zendframework/zend-config-aggregator": "^1.0",
"zendframework/zend-diactoros": "^1.7.1 || ^2.0",
"zendframework/zend-expressive": "^3.0.1",
"zendframework/zend-expressive-helpers": "^5.0",
"zendframework/zend-stdlib": "^3.1",
"zendframework/zend-servicemanager": "^3.3",
"zendframework/zend-expressive-fastroute": "^3.0",
"zendframework/zend-expressive-twigrenderer": "^2.0"
},
"require-dev": {
"filp/whoops": "^2.1.12",
"php-middleware/php-debug-bar": "^3.0",
"phpunit/phpunit": "^7.0.1",
"roave/security-advisories": "dev-master",
"squizlabs/php_codesniffer": "^2.9.1",
"zendframework/zend-expressive-tooling": "^1.0",
"zfcampus/zf-development-mode": "^3.1"
},
"autoload": {
"psr-4": {
"App\\": "src/App/src/",
"PhpDebugBar\\": "src/PhpDebugBar/src/"
}
},
"autoload-dev": {
"psr-4": {
"AppTest\\": "test/AppTest/"
}
},
"scripts": {
"post-create-project-cmd": [
"#development-enable"
],
"development-disable": "zf-development-mode disable",
"development-enable": "zf-development-mode enable",
"development-status": "zf-development-mode status",
"expressive": "expressive --ansi",
"check": [
"#cs-check",
"#test"
],
"clear-config-cache": "php bin/clear-config-cache.php",
"cs-check": "phpcs",
"cs-fix": "phpcbf",
"serve": "php -S 0.0.0.0:8080 -t public/",
"test": "phpunit --colors=always",
"test-coverage": "phpunit --colors=always --coverage-clover clover.xml"
}
}

I figured it out. The instructions at https://docs.zendframework.com/zend-expressive/v3/cookbook/debug-toolbars/ are correct. The only additional step which is required is adding invokables and aliases entries to the configuration.
Mine were in /config/autoload/zend-expressive-tooling-factories.global.php:
return [
'dependencies' => [
'invokables' => [
Zend\Diactoros\ResponseFactory::class => Zend\Diactoros\ResponseFactory::class,
Zend\Diactoros\StreamFactory::class => Zend\Diactoros\StreamFactory::class,
],
'aliases' => [
Psr\Http\Message\ResponseFactoryInterface::class => Zend\Diactoros\ResponseFactory::class,
Psr\Http\Message\StreamFactoryInterface::class => Zend\Diactoros\StreamFactory::class,
]
],
];
I originally just had the aliases section and not the invokables section. Once I added that, everything just worked.

try creating an alias first and then provide it to a factory
return [
'dependencies' => [
'factories' => [
Psr\Http\Message\ResponseInterface::class => Zend\Diactoros\ResponseFactory::class,
'Psr\Http\Message\StreamFactoryInterface' => Zend\Diactoros\StreamFactory::class,
],
'aliases' => [
ClassThatImplementsResponseInterface::class => Psr\Http\Message\ResponseInterface::class,
ClassThatImplementsStreamFactoryInterface::class => 'Psr\Http\Message\StreamFactoryInterface',
]
],
];
UPDATE:
As #d.lanza38 discovered this is the wright configuration
return [
'dependencies' => [
'invokables' => [
Zend\Diactoros\ResponseFactory::class => Zend\Diactoros\ResponseFactory::class,
Zend\Diactoros\StreamFactory::class => Zend\Diactoros\StreamFactory::class,
],
'aliases' => [
Psr\Http\Message\ResponseFactoryInterface::class => Zend\Diactoros\ResponseFactory::class,
Psr\Http\Message\StreamFactoryInterface::class => Zend\Diactoros\StreamFactory::class,
]
],
];

I am writing an other answer as it is easier to read.
OK. I just did a fresh install of Zend Expressive 3 and https://github.com/php-middleware/phpdebugbar:
composer require --dev php-middleware/php-debug-bar
composer dump-autoload
Created /config/autoload/debugbar.local.php
return array_merge(PhpMiddleware\PhpDebugBar\ConfigProvider::getConfig(), [
'phpmiddleware' => [
'phpdebugbar' => [
'javascript_renderer' => [
'base_url' => '/razvan.ionascu/ze-api/public',
],
'collectors' => [
DebugBar\DataCollector\ConfigCollector::class, // Service names of collectors
],
'storage' => null, // Service name of storage
],
],
'dependencies' => [
'factories' => [
\PhpMiddleware\PhpDebugBar\PhpDebugBarMiddleware::class => \PhpMiddleware\PhpDebugBar\PhpDebugBarMiddlewareFactory::class,
\DebugBar\DataCollector\ConfigCollector::class => \PhpMiddleware\PhpDebugBar\ConfigCollectorFactory::class,
\PhpMiddleware\PhpDebugBar\ConfigProvider::class => \PhpMiddleware\PhpDebugBar\ConfigProvider::class,
\DebugBar\DebugBar::class => \PhpMiddleware\PhpDebugBar\StandardDebugBarFactory::class,
JavascriptRenderer::class => NewJavascriptRendererFactory::class,
],
],
]);
For this to work you need to create a new JavascriptRendererFactory. The current one seaches for the wrong config key, ConfigProvider::class instead of 'config' :
class NewJavascriptRendererFactory
{
public function __invoke(ContainerInterface $container): JavascriptRenderer
{
$debugbar = $container->get(DebugBar::class);
$config = $container->get('config');
$rendererOptions = $config['phpmiddleware']['phpdebugbar']['javascript_renderer'];
$renderer = new JavascriptRenderer($debugbar);
$renderer->setOptions($rendererOptions);
return $renderer;
}
}
added the following aliases and factories to /confog/atuoload/dependencies.global.php
'aliases' => [
\Psr\Http\Message\ResponseFactoryInterface::class => ResponseFactory::class,
\Psr\Http\Message\StreamFactoryInterface::class => StreamFactory::class,
],
'factories' => [
...
\DebugBar\JavascriptRenderer::class => JavascriptRendererFactory::class,
...
],
Added a new pipeline to /config/pipeline.php
//only works in development mode
if (!empty($container->get('config')['debug'])) {
$app->pipe(\PhpMiddleware\PhpDebugBar\PhpDebugBarMiddleware::class);
}
As I mentioned in an earlier comment, I have also configured https://docs.zendframework.com/zend-servicemanager/reflection-abstract-factory/ , so I don't need to create a factory for each service()
See the working debug bar here

Related

Could not find package drush/drush

I'm facing a problem while I'm running this commmand composer require drush/drush but it didn't work for me and I got this error message:
[InvalidArgumentException] Could not find package drush/drush. It
was however found via repository search, which indicates a consistency
issue with the repository.
I'm using Drupal 8.9.18, Drush version : 10.6.1 and my PHP version is: php7.1.33
my composer.json file :
{
"name": "drupal/legacy-project",
"description": "Project template for Drupal 8 projects with composer following drupal/drupal layout",
"type": "project",
"license": "GPL-2.0-or-later",
"homepage": "https://www.drupal.org/project/drupal",
"support": {
"docs": "https://www.drupal.org/docs/user_guide/en/index.html",
"chat": "https://www.drupal.org/node/314178"
},
"repositories": {
"drupal": {
"type": "composer",
"url": "https://packages.drupal.org/8"
},
"0": {
"type": "composer",
"url": "https://packages.drupal.org/8"
},
"gigyadrupal": {
"type": "git",
"url": "https://github.com/gigya/drupal8.git"
}
},
"require": {
"composer/installers": "^1.2",
"drupal/core-composer-scaffold": "^8.8",
"drupal/core-project-message": "^8.8",
"drupal/core-recommended": "^8.8",
"drupal/core-vendor-hardening": "^8.8",
"drupal/gigya": "^1.7"
},
"conflict": {
"drupal/drupal": "*"
},
"minimum-stability": "dev",
"prefer-stable": true,
"config": {
"sort-packages": true
},
"extra": {
"drupal-scaffold": {
"locations": {
"web-root": "./"
}
},
"installer-paths": {
"core": [
"type:drupal-core"
],
"libraries/{$name}": [
"type:drupal-library"
],
"modules/contrib/{$name}": [
"type:drupal-module"
],
"profiles/contrib/{$name}": [
"type:drupal-profile"
],
"themes/contrib/{$name}": [
"type:drupal-theme"
],
"drush/Commands/contrib/{$name}": [
"type:drupal-drush"
],
"modules/custom/{$name}": [
"type:drupal-custom-module"
],
"themes/custom/{$name}": [
"type:drupal-custom-theme"
]
},
"drupal-core-project-message": {
"include-keys": [
"homepage",
"support"
],
"post-create-project-cmd-message": [
"<bg=blue;fg=white> </>",
"<bg=blue;fg=white> Congratulations, you’ve installed the Drupal codebase </>",
"<bg=blue;fg=white> from the drupal/legacy-project template! </>",
"<bg=blue;fg=white> </>",
"",
"<bg=yellow;fg=black>Next steps</>:",
" * Install the site: https://www.drupal.org/docs/8/install",
" * Read the user guide: https://www.drupal.org/docs/user_guide/en/index.html",
" * Get support: https://www.drupal.org/support",
" * Get involved with the Drupal community:",
" https://www.drupal.org/getting-involved",
" * Remove the plugin that prints this message:",
" composer remove drupal/core-project-message"
]
}
}
}
You need to have an installable set of packages. drupal/gigya doesn't really exist (anymore). You also should not be using the drupal/legacy-project at all.
This is the best I came up with, although that's maybe not giving you the version of Gigya you want. Not sure, try it out. Check the updated respositories section and the updated "gigya/gigya-drupal": "*" package name which will always get you the latest master from GitHub.
{
"name": "drupal/legacy-project",
"description": "Project template for Drupal 8 projects with composer following drupal/drupal layout",
"type": "project",
"license": "GPL-2.0-or-later",
"homepage": "https://www.drupal.org/project/drupal",
"support": {
"docs": "https://www.drupal.org/docs/user_guide/en/index.html",
"chat": "https://www.drupal.org/node/314178"
},
"repositories": [
{
"type": "composer",
"url": "https://packages.drupal.org/8"
},
{
"type": "vcs",
"url": "https://github.com/gigya/drupal8"
}
],
"require": {
"composer/installers": "^1.2",
"drupal/core-composer-scaffold": "^8.8",
"drupal/core-project-message": "^8.8",
"drupal/core-recommended": "^8.8",
"drupal/core-vendor-hardening": "^8.8",
"gigya/gigya-drupal": "*"
},
"conflict": {
"drupal/drupal": "*"
},
"minimum-stability": "dev",
"prefer-stable": true,
"config": {
"sort-packages": true
},
"extra": {
"drupal-scaffold": {
"locations": {
"web-root": "./"
}
},
"installer-paths": {
"core": [
"type:drupal-core"
],
"libraries/{$name}": [
"type:drupal-library"
],
"modules/contrib/{$name}": [
"type:drupal-module"
],
"profiles/contrib/{$name}": [
"type:drupal-profile"
],
"themes/contrib/{$name}": [
"type:drupal-theme"
],
"drush/Commands/contrib/{$name}": [
"type:drupal-drush"
],
"modules/custom/{$name}": [
"type:drupal-custom-module"
],
"themes/custom/{$name}": [
"type:drupal-custom-theme"
]
},
"drupal-core-project-message": {
"include-keys": [
"homepage",
"support"
],
"post-create-project-cmd-message": [
"<bg=blue;fg=white> </>",
"<bg=blue;fg=white> Congratulations, you’ve installed the Drupal codebase </>",
"<bg=blue;fg=white> from the drupal/legacy-project template! </>",
"<bg=blue;fg=white> </>",
"",
"<bg=yellow;fg=black>Next steps</>:",
" * Install the site: https://www.drupal.org/docs/8/install",
" * Read the user guide: https://www.drupal.org/docs/user_guide/en/index.html",
" * Get support: https://www.drupal.org/support",
" * Get involved with the Drupal community:",
" https://www.drupal.org/getting-involved",
" * Remove the plugin that prints this message:",
" composer remove drupal/core-project-message"
]
}
}
}

Visual Studio File Nesting for gRPC proto files

I have a load of .proto files that generate an associated .cs file, and i also have a partial .cs file, all of the same name:
message.proto
message.cs (autogenerated in the obj\debug
directory)
mesasge.cs (in the same folder as the proto file)
I am trying to get them nesting with Visual Studio 2019, but unable. Pointers much appreciated as to what i am doing wrong.
{
"help": "https://go.microsoft.com/fwlink/?linkid=866610",
"root": true,
"dependentFileProviders": {
"add": {
"addedExtension": {},
"pathSegment": {
"add": {
".*": [
".js",
".css",
".html",
".htm",
".less",
".scss",
".coffee",
".iced",
".config",
".cs",
".vb",
".json",
".proto"
]
}
},
"extensionToExtension": {
"add": {
".proto": [
".cs"
],
".js": [
".coffee",
".iced",
".ts",
".tsx",
".jsx"
],
".css": [
".less",
".scss",
".sass",
".styl"
],
".html": [
".md",
".mdown",
".markdown",
".mdwn"
],
".map": [
".js",
".css"
],
".svgz": [
".svg"
],
".designer.cs": [
".resx"
],
".cs.d.ts": [
".cs"
]
}
},
"fileToFile": {
"add": {
".bowerrc": [
"bower.json"
],
".npmrc": [
"package.json"
],
"npm-shrinkwrap.json": [
"package.json"
],
"yarn.lock": [
"package.json"
],
".yarnclean": [
"package.json"
],
".yarnignore": [
"package.json"
],
".yarn-integrity": [
"package.json"
],
".yarnrc": [
"package.json"
],
"package-lock.json": [
"package.json"
]
}
},
"fileSuffixToExtension": {
"add": {
"-vsdoc.js": [
".js"
]
}
},
"allExtensions": {
"add": {
".*": [
".tt"
]
}
}
}
}
}

Laravel Collective does not work

I am trying to learn Laravel using the Laracasts and it's very interesting.
In the step of creating forms, I would like to use Laravel Collective. So I went to the website http://laravelcollective.com/docs/5.1/html and tried what's written, but I get the following error:
FatalErrorException in ProviderRepository.php line 146:
Class 'Collective\Html\HtmlServiceProvider' not found
Here's my code:
app.php
'providers' => [
...
Illuminate\View\ViewServiceProvider::class,
Collective\Html\HtmlServiceProvider::class,
...
],
'aliases' => [
...
'View' => Illuminate\Support\Facades\View::class,
'Form' => Collective\Html\FormFacade::class,
'Html' => Collective\Html\HtmlFacade::class
],
composer.json
"require": {
"php": ">=5.5.9",
"laravel/framework": "5.1.*",
"laravelcollective/html": "5.1.*"
},
Any idea what I can do to solve my problem?

Laravel add PicoFeed class for laravel

i'm installing PicoFeed from composer with this configuration on composer.json
"repositories": [
{
"type": "package",
"package": {
"name": "fguillot/picoFeed",
"version": "dev-master",
"source": {
"url": "https://github.com/fguillot/picoFeed",
"type": "git",
"reference": "origin/master"
}
}
}
],
"require": {
"laravel/framework": "4.2.*",
"fguillot/picoFeed": "dev-master"
},
now i think i must be define this class into app.php such as providers and aliases after set this line
'Reader' =>'fguillot\picoFeed\picofeed',
in aliases and try to use :
Route::get('/feed', array('as' => 'feed', function () {
try {
$reader = new Reader;
$resource = $reader->download('http://linuxfr.org/news.atom');
$parser = $reader->getParser(
$resource->getUrl()
);
$feed = $parser->execute();
echo $feed;
}
catch (Exception $e) {
echo $e;
}
}));
i get this error:
exception 'ErrorException' with message 'Class 'fguillot\picoFeed\picofeed' not found' in /var/www/livedata/vendor/laravel/framework/src/Illuminate/Foundation/AliasLoader.php:64
how to add this class to providers on app.php file
You are not using the right class
'Reader' => 'PicoFeed\Reader\Reader';
Or
'Reader' => PicoFeed\Reader\Reader::class;
try this. If you have a IDE like phpstorm you will see warning if its not there.

Changing controller path

Alright so i've been trying to change my controller path (so my project is more structured) but sadly everytime i try to route with the controller like so:
Route::get('/', ['as' => 'home', 'uses' => 'PagesController#index']);
Now that returns me a error page:
ReflectionException
Class PagesController does not exist
So I think let me psr-4 autoload it and/or add it in the classmap so this is what my composer.json looks like:
{
"name": "laravel/laravel",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"license": "MIT",
"require": {
"laravel/framework": "4.2.*",
"cartalyst/sentinel": "dev-master",
"guzzlehttp/guzzle": "4.*",
"way/generators": "2.*"
},
"repositories": [
{
"type": "composer",
"url": "http://packages.cartalyst.com"
}
],
"autoload": {
"classmap": [
"app/database/migrations",
"app/database/seeds",
"app/strifemods/Controllers",
"app/strifemods/Models"
],
"psr-4": {
"Strifemods\\": "app/Strifemods"
}
},
"scripts": {
"post-install-cmd": [
"php artisan clear-compiled",
"php artisan optimize"
],
"post-update-cmd": [
"php artisan clear-compiled",
"php artisan optimize"
],
"post-create-project-cmd": [
"php artisan key:generate"
]
},
"config": {
"preferred-install": "dist"
},
"minimum-stability": "dev",
"prefer-stable": true
}
After that it's still not working so i decide to look over in my dear /vendor/composer/ directory to see if its actually being loaded.
// autoload_classmap.php #generated by Composer
$vendorDir = dirname(dirname(__FILE__));
$baseDir = dirname($vendorDir);
return array(
'CreateSessionTable' => $baseDir . '/app/database/migrations/2014_07_06_213148_create_session_table.php',
'DatabaseSeeder' => $baseDir . '/app/database/seeds/DatabaseSeeder.php',
'IlluminateQueueClosure' => $vendorDir . '/laravel/framework/src/Illuminate/Queue/IlluminateQueueClosure.php',
'MigrationCartalystSentinelAlterThrottle' => $vendorDir . '/cartalyst/sentinel/src/migrations/2013_11_26_025024_migration_cartalyst_sentinel_alter_throttle.php',
'MigrationCartalystSentinelAlterUsers' => $vendorDir . '/cartalyst/sentinel/src/migrations/2013_11_26_023520_migration_cartalyst_sentinel_alter_users.php',
'MigrationCartalystSentinelInstallActivations' => $vendorDir . '/cartalyst/sentinel/src/migrations/2013_11_26_014954_migration_cartalyst_sentinel_install_activations.php',
'MigrationCartalystSentinelInstallGroups' => $vendorDir . '/cartalyst/sentinel/src/migrations/2012_12_06_225929_migration_cartalyst_sentinel_install_groups.php',
'MigrationCartalystSentinelInstallReminders' => $vendorDir . '/cartalyst/sentinel/src/migrations/2013_11_26_022418_migration_cartalyst_sentinel_install_reminders.php',
'MigrationCartalystSentinelInstallThrottle' => $vendorDir . '/cartalyst/sentinel/src/migrations/2012_12_06_225988_migration_cartalyst_sentinel_install_throttle.php',
'MigrationCartalystSentinelInstallUsers' => $vendorDir . '/cartalyst/sentinel/src/migrations/2012_12_06_225921_migration_cartalyst_sentinel_install_users.php',
'MigrationCartalystSentinelInstallUsersGroupsPivot' => $vendorDir . '/cartalyst/sentinel/src/migrations/2012_12_06_225945_migration_cartalyst_sentinel_install_users_groups_pivot.php',
'MigrationCartalystSentinelRenameAlterGroups' => $vendorDir . '/cartalyst/sentinel/src/migrations/2013_11_26_023945_migration_cartalyst_sentinel_rename_alter_groups.php',
'MigrationCartalystSentinelRenameAlterGroupsUsersPivot' => $vendorDir . '/cartalyst/sentinel/src/migrations/2013_11_26_024557_migration_cartalyst_sentinel_rename_alter_groups_users_pivot.php',
'SessionHandlerInterface' => $vendorDir . '/symfony/http-foundation/Symfony/Component/HttpFoundation/Resources/stubs/SessionHandlerInterface.php',
'Strifemods\\Controllers\\BaseController' => $baseDir . '/app/strifemods/Controllers/BaseController.php',
'Strifemods\\Controllers\\PagesController' => $baseDir . '/app/strifemods/Controllers/PagesController.php',
'Whoops\\Module' => $vendorDir . '/filp/whoops/src/deprecated/Zend/Module.php',
'Whoops\\Provider\\Zend\\ExceptionStrategy' => $vendorDir . '/filp/whoops/src/deprecated /Zend/ExceptionStrategy.php',
'Whoops\\Provider\\Zend\\RouteNotFoundStrategy' => $vendorDir . '/filp/whoops/src/deprecated/Zend/RouteNotFoundStrategy.php',
);
And it is being loaded but it cant find the class, can anyone shed some light on this and help me out ;) would appriciate it.
The error is technically correct. Although PagesController exists, it only exists in that somewhere there's a class with that name. Since the class is namespaced however, it should be referred to as Strifemods\Controllers\PagesController except for when in the context of Strifemods\Controllers.
Using your routes as an example, you'd do it like so:
Route::get('/', [
'as' => 'home',
'uses' => 'Strifemods\Controllers\PagesController#index'
]);
Should you have sub-namespaces within your controllers, say API and Admin, you can do something like the following:
Route::group(['namespace' => 'Strifemods\Controllers\API'], function()
{
Route::get('/', [
'as' => 'api.home',
'uses' => 'PagesController#index'
]);
});
Route::group(['namespace' => 'Strifemods\Controllers\Admin'], function()
{
Route::get('/', [
'as' => 'admin.home',
'uses' => 'PagesController#index'
]);
});
That allows you to have Strifemods\Controllers\API\PagesController and Strifemods\Controllers\Admin\PagesController. Hope that helps.
That is how you can make your project more structured:
Every route file (web.php, api.php ...) declared in a map() method, in a file
\app\Providers\RouteServiceProvider.php
when you mapping a route file you can set a ->namespace($this->namespace) for it, you will see it there among examples.
It means that you can create more files to make your project more structured!
And set different namespaces for each of them.
But I prefer set empty string for the namespace ""
it gives you set your controllers to rout in a native php way, see the example:
Route::resource('/users', UserController::class);
Route::get('/agents', [AgentController::class, 'list'])->name('agents.list');
Now you can double click your controller names in your IDE to get there quickly and conveniently.

Resources