I am having some issues with developing a package. I have read through several tutorials on the web and followed their advice but for some reason I still run into the same issue.
What I am trying to do: Develop a package in an active project
In my Laravel folder, I have a packages/companyname/laravel-model-notes. Inside that package, I have a composer.json file with the following:
{
"name": "companyname/laravel-model-notes",
"description": "A package to add notes to an eloquent model in Laravel.",
"type": "library",
"require": {},
"config": {
"sort-packages": true
},
"autoload": {
"psr-4": {
"CompanyName\LaravelModelNotes\": "src"
}
},
"autoload-dev": {
"psr-4": {
"CompanyName\LaravelModelNotes\Tests\": "tests"
}
},
"extra": {
"laravel": {
"providers": [
"CompanyName\LaravelModelNotes\NoteServiceProvider"
]
}
}
}
And then in my laravel composer.json file, I have added the following:
"autoload": {
"psr-4": {
"App\": "app/",
"CompanyName\LaravelModelNotes\": "packages/companyname/laravel-model-notes/src"
},
"classmap": [
"database/seeds",
"database/factories"
],
"files": [
"app/Helpers/ThemeHelper.php",
"app/Helpers/BaseHelper.php"
]
},
When I manually add the service provider to the App.php things work, however artisan commands like publishing the migrations does not work. For some reason, Laravel does not see the package?
Is there some special way of building a package inside of a project and having that project recognize the package?
I am using Laravel 7.
Below is my service provider:
class NoteServiceProvider extends ServiceProvider
{
/**
* Bootstrap the application services.
*/
public function boot()
{
if ($this->app->runningInConsole()) {
$this->publishes([
__DIR__.'/../config/config.php' => config_path('notes.php'),
], 'config');
if (! class_exists('CreateNotesTable')) {
// TODO: If tenant folder exists publish there too.
$this->publishes([
__DIR__.'/../database/migrations/create_notes_table.php.stub' => database_path('migrations/'.date('Y_m_d_His', time()).'_create_notes_table.php'),
], 'migrations');
}
}
}
/**
* Register the application services.
*/
public function register()
{
$this->mergeConfigFrom(__DIR__.'/../config/config.php', 'notes');
}
}
question from:
https://stackoverflow.com/questions/65835981/properly-create-a-laravel-package