简体   繁体   中英

Laravel controllers and routes in packages?

I'm having trouble registering controllers to routes in my package.

As far as I understand from the official documentation I just need to simply prefix it and use my namespace though I always get the error of xyzclass not found.

Anyone could explain to me how can I make this work?

-- Vendor -- Package |-- composer.json |-- composer.lock |-- public |-- src | |-- Vendor | | -- Package | | -- PackageServiceProvider.php | |-- config | |-- controllers | | -- MyController.php | |-- lang | |-- migrations | |-- routes.php | -- views |-- tests

I loaded my routes.php in my serviceprovider file. I created and index function in MyController.php and assigned it in my routes.php.

Route::contorller('myctrl', 'Vendor\Package\MyController');

And in theory I should be able to access mydomain.com/myctrl and it should give me back what I defined in MyController's index function. But in reality I get an error saying Class Vendor\\Package\\MyController does not exists. Any advice or help how should this work or how it's working?

Route::contorller('myctrl', 'MyController');

这与src/controllers/链接到vendor

Guess I'm dumb, forgot some little details. I should use a proper namespace next time, and adding the controllers folder to my composer.json helped too.

I found a nice and detailed description on how to do this here: https://stackoverflow.com/a/18137352/1397967

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM