Package Update
1. Update composer.json
Change the package version in your composer.json:
{ "require": { "moonshine/moonshine": "^3.0" }}
2. Create Backups
Before updating, you need to back up the following files:
mv config/moonshine.php config/moonshine_old.phpmv app/Providers/MoonShineServiceProvider.php app/Providers/MoonShineServiceProvider_old.phpmv app/MoonShine/Pages/Dashboard.php app/MoonShine/Pages/Dashboard_old.php
These files will be needed for transferring configurations and settings. See the Changelog section.
3. Update Application Configuration
If you have Laravel < 11, you need to find and remove App\Providers\MoonShineServiceProvider::class
from the config/app.php
configuration.
After running the moonshine:install
command, the service provider will be added automatically.
4. Run the Update
composer update
Initial Setup
1. Install the New Version
Run the command:
php artisan moonshine:install
This command will create:
- A new service provider
- Updated configuration
- A new Layout
- A new Dashboard
2. Migrate Settings
- Transfer the parameters from the old config (
moonshine_old.php
) to the new one. See the documentation on configuration. - The menu structure has changed in the new version:
- Open
app/MoonShine/Layouts/MoonShineLayout.php
. - Copy the old menu from
MoonShineServiceProvider_old.php
to themenu
method. - Remove the
heroicons.outline.
prefix from icons. - Update all resource instances to string classes:
// WasMenuItem::make('Settings', new SettingResource(), 'heroicons.outline.adjustments-vertical') // NowMenuItem::make('Settings', SettingResource::class, 'adjustments-vertical')
3. Register Resources and Pages
In the new MoonShineServiceProvider.php
, you need to register all resources and pages:
$core->resources([ MoonShineUserResource::class, MoonShineUserRoleResource::class, // Add all your resources]); $core->pages([ ...$config->getPages(), SettingPage::class,]);
Commands to generate lists:
For importing namespaces:
find app/MoonShine/Resources -type f | sed "s/app/use App/" | sed "s|/|\\\|g" | sed "s/.php/;/" | sort
For the list of resources:
find app/MoonShine/Resources -type f -exec basename {} \; | sed "s/.php/::class,/" | sort
4. Update Dashboard
- Move required components from
Dashboard_old.php
to the newDashboard.php
. - Take note of the changes in the Changelog section.
5. Remove Old Files
After successful migration, remove:
# Old Layout (if it exists)rm app/MoonShine/MoonShineLayout.php # Backups of files from 2.xrm config/moonshine_old.phprm app/Providers/MoonShineServiceProvider_old.phprm app/MoonShine/Pages/Dashboard_old.php
Changelog
Namespaces
Main Changes
MoonShine\Resources\ → MoonShine\Laravel\Resources\MoonShine\Fields\Relationships\ → MoonShine\Laravel\Fields\Relationships\MoonShine\Fields\Slug → MoonShine\Laravel\Fields\SlugMoonShine\Fields\ → MoonShine\UI\Fields\MoonShine\Decorations\Block → MoonShine\UI\Components\Layout\BoxMoonShine\Decorations\ → MoonShine\UI\Components\Layout\* (some to MoonShine\UI\Components\, check manually)MoonShine\Enums\ → MoonShine\Support\Enums\MoonShine\Pages\ → MoonShine\Laravel\Pages\MoonShine\Models\ → MoonShine\Laravel\Models\MoonShine\QueryTags\ → MoonShine\Laravel\QueryTags\MoonShine\Attributes\ → MoonShine\Support\Attributes\MoonShine\Components\ → MoonShine\UI\Components\MoonShine\Metrics\ → MoonShine\UI\Components\Metrics\Wrapped\MoonShine\ActionButtons\ → MoonShine\UI\Components\MoonShine\Http\Responses\ → MoonShine\Laravel\Http\Responses\MoonShine\Http\Controllers\ → MoonShine\Laravel\Http\Controllers\MoonShine\MoonShineAuth → MoonShine\Laravel\MoonShineAuth
Additional Packages
If needed, install and update namespaces for:
-
MoonShine\Laravel\Handlers\ExportHandler
-
MoonShine\Laravel\Handlers\ImportHandler
-
MoonShine\UI\Components\Metrics\Wrapped\DonutChartMetric
-
MoonShine\UI\Components\Metrics\Wrapped\LineChartMetric
-
MoonShine\Fields\Code
-
MoonShine\Fields\Markdown
-
MoonShine\Fields\TinyMce
Methods
Main Changes
- Creating instances of resources and pages:
// Wasnew NameResource() // Now// Recommended via DI// or:app(NameResource::class)
- Method signatures:
// Waspublic function components(): arraypublic function title(): stringpublic function breadcrumbs(): stringpublic function rules(Model $item): arrayprotected function afterUpdated(Model $user): Modelpublic function detailButtons(): arraypublic function modifyListComponent(MoonShineRenderable|TableBuilder $table): MoonShineRenderable$field->getData()detailPageUrlMoonShineAuth::guard()getActiveActions() // Nowprotected function components(): iterablepublic function getTitle(): stringpublic function getBreadcrumbs(): stringprotected function rules($item): arrayprotected function afterUpdated($user): Modelpublic function detailButtons(): ListOfpublic function modifyListComponent(ComponentContract $table): ComponentContract$field->getData()->getOriginal()getDetailPageUrlMoonShineAuth::getGuard()activeActions()
- Changes in field methods:
// Waspublic function fields(): array // Nowprotected function indexFields(): iterable // only accepts fieldsprotected function detailFields(): iterableprotected function formFields(): iterable
- Table attributes:
// New formatTableBuilder::make() ->tdAttributes(fn(mixed $data, int $row, TableBuilder $table): array => $row === 3 ? ['class' => 'bgc-yellow'] : [] ) ->tdAttributes(fn(mixed $data, int $row, int $cell, TableBuilder $table): array => $cell === 3 ? ['align' => 'right'] : [] )
- Changes in other methods:
- Helper
to_page
→toPage
- Instead of the
columnSpan
method in components, use the component methodColumn
:Column::make([...])->columnSpan(..)
- Instead of
expansion('url')
, use thesuffix('url')
method
Removed Methods
- Field display methods:
- hideOnIndex, showOnIndex
- hideOnForm, showOnForm
- hideOnCreate, showOnCreate
- hideOnUpdate, showOnUpdate
- hideOnDetail, showOnDetail
- hideOnAll
- hideOnExport, showOnExport
- useOnImport (use the import-export package)
- Helpers:
- form
- table
- actionBtn
Variables
Main Changes
- Icons:
- Remove the
heroicons.outline
andheroicons.solid
prefixes. - These icons are now available by default.
- Menu:
// WasMenuItem::make('Settings', new SettingResource(), 'heroicons.outline.adjustments-vertical') // NowMenuItem::make('Settings', SettingResource::class, 'adjustments-vertical')
- Asynchronous events:
// Was->async(asyncUrl: ..., asyncEvents: ...)'table-updated-{name}' // Now->async(url: ..., events: ...)AlpineJs::event(JsEvent::TABLE_UPDATED, {name})
- Sort direction:
// Wasprotected string $sortDirection = 'ASC'; // Nowprotected SortDirection $sortDirection = SortDirection::ASC;
- Assets:
// Was$assets // strings // Now$assets // accepts AssetElementContract, such as Css, InlineCss, Js, InlineJsFor management, use [AssetManager](/docs/3.x/appearance/assets).
Removed Variables
-
protected bool $isAsync = true;
(now enabled by default)