I am currently trying to develop a custom Laravel Package, but is having some issues with getting started.
This is my file structure:
-packages
- oliverbusk
-invoiceconverter
-src
-controllers
- InvoiceconverterController.php
-resources
- views
- home.blade.php
-routes
- web.php
- InvoiceConverterServiceProvider.php
So as you can see, I have my files inside the src/ folder.
First of all, this is my composer.json, inside my package folder:
"extra": {
"laravel": {
"providers": [
"Oliverbusk\\Invoiceconverter\\InvoiceConverterServiceProvider"
]
}
}
I have then autoloaded this in my projects main composer.json file:
"require": {
//....
"oliverbusk/invoiceconverter": "dev-feature-package"
},
"autoload": {
[...]
"psr-4": {
"App\\": "app/",
"Oliverbusk\\Invoiceconverter\\": "packages/oliverbusk/invoiceconverter"
}
},
This is my serviceprovider file:
namespace Oliverbusk\Invoiceconverter;
use Illuminate\Support\ServiceProvider;
class InvoiceConverterServiceProvider extends ServiceProvider
{
/**
* Bootstrap services.
*
* @return void
*/
public function boot()
{
//Load our routes
$this->loadRoutesFrom(__DIR__ . '/routes/web.php');
//Load our views
$this->loadViewsFrom(__DIR__ . '/resources/views', 'invoiceconverter');
}
/**
* Register services.
*
* @return void
*/
public function register()
{
//
}
}
And my controller file, located in controllers/:
namespace Oliverbusk\Invoiceconverter\Controllers;
use App\Http\Controllers\Controller;
class InvoiceconverterController extends Controller
{
public function index()
{
return view('invoiceconverter::home');
}
}
Last, my routes/web.php file:
Route::group(['namespace' => 'Oliverbusk\InvoiceConverter\Controllers'], function () {
Route::get('invoiceconverter', 'InvoiceconverterController@index');
});
Error :
Class Oliverbusk\InvoiceConverter\Controllers\InvoiceconverterController does not exist
Bonus info:
Composer dump autoload shows the following:
Discovered Package: oliverbusk/invoiceconverter
- I have already tried to clear the cache with
php artisan:cache:clear. - I have also tried
composer update
php artisan vendor:publishcontrollersdirectory is capitalised to match the namespace, so it should beControllers. That could well be it though. Same goes for your class name and the file it is in, try to keep the same casing.Controllers- did not work.