Custom Laravel Package with Nova Resources & Laravel Models [help needed] #6558
Replies: 1 comment
-
Hey! 👋 You’re on the right track with creating a custom Laravel package and connecting it with Nova. Here’s a structured approach to ensure your models and Nova resources are properly recognized within your custom package: 1. Ensure the Package Service Provider is RegisteredFirst, make sure your package’s service provider is registered. You can confirm this by checking that it’s loaded in your In namespace NowakAdmin\SomePackage;
use Illuminate\Support\ServiceProvider;
use Laravel\Nova\Nova;
class SomePackageServiceProvider extends ServiceProvider
{
/**
* Register any package services.
*/
public function register(): void
{
$this->mergeConfigFrom(__DIR__.'/../config/namsbase.php', 'namsbase');
// Register the package's models or other bindings here.
$this->app->singleton('namsbase', function ($app) {
return new NamsBase;
});
}
/**
* Bootstrap any package services.
*/
public function boot(): void
{
if ($this->app->runningInConsole()) {
// Load migrations if you have them
$this->loadMigrationsFrom(__DIR__.'/../database/migrations');
}
// Register Nova resources if they exist
Nova::resources([
\NowakAdmin\SomePackage\Nova\YourNovaResource::class,
// Add other Nova resources as needed
]);
// Load routes, views, etc. if applicable
$this->loadRoutesFrom(__DIR__.'/../routes/web.php');
$this->loadViewsFrom(__DIR__.'/../resources/views', 'somepackage');
}
} 2. Configure the
|
Beta Was this translation helpful? Give feedback.
-
Hello everyone.
I'm very fresh with managing composer/laravel packages and after my research i cannot accomplish my goal.
What I did:
I used this package to create shell for my own package:
composer require jeroen-g/laravel-packager --dev
created a shell package:
php artisan packager:new NowakAdmin SomePackage
Then I added folders:
Packages\NowakAdmin\SomePackage\src\Models <- there i putted my models files
Packages\NowakAdmin\SomePackage\src\Nova <- there i putted my nova resources files
Then i made a Github private repository of them, added to composer.json:
removed package from /Packages/:
php artisan packager:remove NowakAdmin SomePackage
Finally composer update - no errors, downloaded from github, installed.
But no models / resources loaded (not showing in nova menu)
I tried to do something simplier for beginning so I added code in
Above code work and overrides footer and logo of Nova. But idk if this is a good place to put this code to.
in composer.json whole src is loaded
And in models i tried fewsolutions:
as in anwser post: https://stackoverflow.com/questions/19133020/using-models-on-packages
or as in https://www.laravelpackage.com/08-models-and-migrations/
The sources of above are somewaht old (2011/ 2018) and i assume that nowdays it should be done in other way.
Also i did not find anything about adding models to packages in Laravel docs:
https://laravel.com/docs/11.x/packages
I assume that mby I just need to make some Nova Menu hook in my package? (it's in default, fresh-install mode)
I'm Using Laravel 11.27.2 and nova 4.35.3 on php 8.2.22; Hope my english is understandable.
To clarify:
My goal is to have laravel models connected with nova resources inside custom laravel package.
Beta Was this translation helpful? Give feedback.
All reactions