KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I have created a package following the "Creating a Package" instructions in the Laravel 4 documentation . After creating the package I have created a "controllers" folder and a routes file. The new file structure is: /src /Vendor /Package PackageServiceProvider.php /config /controllers /lang /migrations /views routes.php /tests /public I added the routes file to the boot portion of the package service provider: public function boot() { $this->package('vendor/package'); include __DIR__ . '/../../routes.php'; } Then added a basic route to the routes file: Route::get('/package', function() { return "Package route test"; }); Visiting my application at the specified route (app.dev/package) returns the expected: Package route test Then adding a basic controller call to the route (using the default Laravel controller, "HomeController") works: Route::get('/package', 'HomeController@showWelcome'); I then followed this SO answer for setting up the controller for the package. I added the src/controllers folder to the composer classmap, then I dumped the autoloader and checked vendor/composer/autoload_classmap.php and found the class is successfully loaded by composer: <?php // autoload_classmap.php generated by Composer $vendorDir = dirname(__DIR__); $baseDir = dirname($vendorDir); return array( 'HomeController' => $baseDir . '/src/controllers/HomeController.php', ); Now I added the new package controller to the route using the namespace: Route::get('/package', 'Vendor\Package\Controllers\HomeController@showWelcome');
Tags (comma-separated)
Save Edits
Cancel