Custom Laravel Package with Nova Resources & Laravel Models [help needed] #6558
-
Hello everyone. What I did: created a shell package: Then I added folders: Then i made a Github private repository of them, added to composer.json:
removed package from /Packages/: 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:
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: 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: |
Beta Was this translation helpful? Give feedback.
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.
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 Registered
First, make sure your package’s service provider is registered. You can confirm this by checking that it’s loaded in your
composer.json
file (which you’ve done withautoload
), and by using theregister
andboot
methods in your service provider.In
src/SomePackageServiceProvider.php
, you should have something like this: