4
votes

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?

2

2 Answers

1
votes

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

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

This is linked to src/controllers/ not to vendor