- Auto Upgrade
- Package Update
- Namespace Changes
- Resource Structure Changes
- Field Changes
- Layout Changes
- Deprecated Classes and Methods
- Async Methods
Auto Upgrade
To simplify the migration process, you can use the warete/moonshine-upgrade package, which will automatically make all the necessary changes to migrate to MoonShine 4.0.
Package Update
Change the package version to composer.json and update dependencies.
{"require": {"moonshine/moonshine": "^4.0"}}{"require": {"moonshine/moonshine": "^4.0"}}
composer updatecomposer update
Namespace Changes
-use MoonShine\Laravel\Forms\FiltersForm;+use MoonShine\Crud\Forms\FiltersForm;-use MoonShine\Laravel\Forms\LoginForm;+use MoonShine\Crud\Forms\LoginForm;-use MoonShine\Laravel\Http\Responses\MoonShineJsonResponse;+use MoonShine\Crud\JsonResponse;-use MoonShine\Laravel\MoonShineRequest;+use MoonShine\Contracts\Core\DependencyInjection\CrudRequestContract;-use MoonShine\Laravel\Enums\Action;+use MoonShine\Support\Enums\Action;-use MoonShine\Laravel\Enums\Ability;+use MoonShine\Support\Enums\Ability;-use MoonShine\Laravel\Traits\WithComponentsPusher;+use MoonShine\Crud\Traits\WithComponentsPusher;-use MoonShine\Laravel\Forms\FiltersForm;+use MoonShine\Crud\Forms\FiltersForm;-use MoonShine\Laravel\Forms\LoginForm;+use MoonShine\Crud\Forms\LoginForm;-use MoonShine\Laravel\Http\Responses\MoonShineJsonResponse;+use MoonShine\Crud\JsonResponse;-use MoonShine\Laravel\MoonShineRequest;+use MoonShine\Contracts\Core\DependencyInjection\CrudRequestContract;-use MoonShine\Laravel\Enums\Action;+use MoonShine\Support\Enums\Action;-use MoonShine\Laravel\Enums\Ability;+use MoonShine\Support\Enums\Ability;-use MoonShine\Laravel\Traits\WithComponentsPusher;+use MoonShine\Crud\Traits\WithComponentsPusher;
Resource Structure Changes
Many methods and properties have been moved from resources to the corresponding CRUD pages.
The rules() method has been moved from the resource to the FormPage.
The methods metrics(), queryTags(), filters(), etc. have been moved to IndexPage.
The indexButtons() method has been removed from the resource, and the buttons() method in the corresponding index page should be used instead.
This is not a complete list of changes in the resource, but the process of transferring all the relevant functionality from the resource to CRUD pages is quite intuitive and should not be difficult.
Field Changes
Removed the StackFields field, the Fieldset field should be used instead.
-StackFields::make('Title', [- Text::make('Field 1'),- Text::make('Field 2'),-])+Fieldset::make('Title', [+ Text::make('Field 1'),+ Text::make('Field 2'),+])-StackFields::make('Title', [- Text::make('Field 1'),- Text::make('Field 2'),-])+Fieldset::make('Title', [+ Text::make('Field 1'),+ Text::make('Field 2'),+])
Layout Changes
CompactLayout Removed
The CompactLayout has been removed. If you used this layout, go for the standard AppLayout extends.
-use MoonShine\Laravel\Layouts\CompactLayout;+use MoonShine\Laravel\Layouts\AppLayout;-use MoonShine\Laravel\Layouts\CompactLayout;+use MoonShine\Laravel\Layouts\AppLayout;
New Palettes
A palette system has been introduced for managing color schemes. PurplePalette is used by default.
For more information about working with palettes, see the Color Manager section.
MenuItem Changes
The parameters in the MenuItem::make() method have swapped places, now $filler comes first, then $label.
The $label parameter is now optional, by default it is taken from the getLabel() method of the filler.
-MenuItem::make('Settings', SettingResource::class)+MenuItem::make(SettingResource::class)-MenuItem::make('Settings', SettingResource::class)+MenuItem::make(SettingResource::class)
Component changes
In the Profile component, the $withBorder parameter has been removed.
Deprecated Classes and Methods
The following classes and methods are deprecated and will be removed in version 5.0.
Deprecated Classes
| Class | Replacement |
|---|---|
MoonShine\Laravel\Notifications\NotificationButton |
MoonShine\Crud\Notifications\NotificationButton |
MoonShine\Laravel\Http\Responses\MoonShineJsonResponse |
MoonShine\Crud\JsonResponse |
MoonShine\Laravel\MoonShineUI |
Instead of MoonShineUI::toast() now helper toast() |
MoonShine\Laravel\Handlers\Handlers |
MoonShine\Crud\Handlers\BaseHandlers |
MoonShine\Laravel\Handlers\Handler |
MoonShine\Crud\Handlers\BaseHandler |
Deprecated Methods in ModelResource
| Method | Replacement |
|---|---|
getIgnoredFields() |
Moved to IndexPage |
filters() |
Moved to IndexPage |
hasFilters() |
Moved to IndexPage |
queryTags() |
Moved to IndexPage |
hasQueryTags() |
Moved to IndexPage |
handlers() |
Moved to IndexPage |
hasHandlers() |
Moved to IndexPage |
getHandlers() |
Moved to IndexPage |
Deprecated Traits
| Trait | Replacement |
|---|---|
HasFilters |
Moved to IndexPage |
HasQueryTags |
Moved to IndexPage |
HasHandlers |
Moved to IndexPage |
All listed classes and methods will be completely removed in version 5.0. It is recommended to migrate to new alternatives.
Async Methods
All async methods need the #[AsyncMethod] attribute.
Async methods now support "DI".
use MoonShine\Crud\JsonResponse;use MoonShine\Support\Attributes\AsyncMethod;class MyPage extends Page{#[AsyncMethod]public function someAsyncMethod(JsonResponse $response): JsonResponse{return $response->toast('Loaded successfully');}}use MoonShine\Crud\JsonResponse;use MoonShine\Support\Attributes\AsyncMethod;class MyPage extends Page{#[AsyncMethod]public function someAsyncMethod(JsonResponse $response): JsonResponse{return $response->toast('Loaded successfully');}}