I want to have controllers in my Laravel 4 package, but I can't get the routing to work.
I've followed the package instructions in the Laravel 4 documentation, and got the routes.php file working with non-controller routes.
Could someone please give me some instructions on how to get package controllers to work in Laravel 4, it would be very much appreciated.
Thanks in advance.
Lars
// EDIT:
// routes.php
Route::get('admin', 'Package::AdminController@index'); // Does not work
Route::get('admin', function(){ // Works fine
return 'Dashboard';
})
In your package's service provider, have you included your routes file? I don't believe L4 loads the route file automatically. You can do it anywhere but I suspect this would be the most appropriate place to do it.
You'll need to reference the Controller with it's Namespace too
or even
Did you do this:
The autoloader needs to be told about those shiny new classes. I also suggest you check the webserver logs for errors.
I don't know the specifics of your situation, nor do I know if this is the "proper" way to fix this issue, but since I came across the same problem I figured I'd share how I solved it.
I put my package controllers in the controllers subdirectory, so that my directory structure looks like this:
Then, I added the controllers folder to my package's composer.json autoload class map.
Finally, I ran
composer dump-autoload
in the package's root directory, and then reference the controller by name in the routes file.