Advanced

Commands

Use the space key to select the appropriate item.

Installation

Command to install the MoonShine package in your Laravel project:

php artisan moonshine:install
php artisan moonshine:install

Signature:

moonshine:install {--u|without-user} {--m|without-migrations} {--l|default-layout} {--a|without-auth} {--d|without-notifications} {--t|tests-mode}
moonshine:install {--u|without-user} {--m|without-migrations} {--l|default-layout} {--a|without-auth} {--d|without-notifications} {--t|tests-mode}

Available options:

  • --u|without-user - without creating a superuser,
  • --m|without-migrations - without running migrations,
  • --l|default-layout - select the default template (without prompting for a compact theme),
  • --a|without-auth - without authentication,
  • --d|without-notifications - without notifications,
  • --t|tests-mode - test mode.

For more details, refer to the Installation section.

User

Command to create a superuser:

php artisan moonshine:user
php artisan moonshine:user

Signature:

moonshine:user {--u|username=} {--N|name=} {--p|password=}
moonshine:user {--u|username=} {--N|name=} {--p|password=}

Available options:

  • --u|username= - user login/email,
  • --N|name= - user name,
  • --p|password= - password.

Resource

Command to create resources:

php artisan moonshine:resource
php artisan moonshine:resource

Signature:

moonshine:resource {className?} {--type=} {--m|model=} {--t|title=} {--test} {--pest} {--p|policy} {--base-dir=} {--base-namespace=}
moonshine:resource {className?} {--type=} {--m|model=} {--t|title=} {--test} {--pest} {--p|policy} {--base-dir=} {--base-namespace=}

Available options:

  • --m|model= - Eloquent model for the resource model,
  • --t|title= - section title,
  • --type= - quick selection of resource type (1 - default, 2 - with pages, 3 - empty),
  • --p|policy - also create Policy,
  • --test or --pest - additionally generate a test class,
  • --base-dir=, --base-namespace= - change the base directory and namespace of the class.

When creating a resource, several options are available:

  • Default model resource - default model resource with the declaration of fields in the methods indexFields(), formFields() and detailFields(),
  • Model resource with pages - model resource with the publication of the pages IndexPage, FormPage and DetailPage,
  • Empty resource - empty resource for custom implementations.

After executing the command, a resource file will be created in the app/MoonShine/Resources directory. If a model resource with pages is created, additional pages will be created in the app/MoonShine/Pages directory.

Examples:

php artisan moonshine:resource Post --model=CustomPost --title="Articles" php artisan moonshine:resource Post --model="App\Models\CustomPost"
php artisan moonshine:resource Post --model=CustomPost --title="Articles"
 
php artisan moonshine:resource Post --model="App\Models\CustomPost"

For more details, refer to the Model Resources section.

Page

Command to create pages:

php artisan moonshine:page
php artisan moonshine:page

Signature:

moonshine:page {className?} {--force} {--without-register} {--crud} {--dir=} {--extends=} {--base-dir=} {--base-namespace=}
moonshine:page {className?} {--force} {--without-register} {--crud} {--dir=} {--extends=} {--base-dir=} {--base-namespace=}

Available options:

  • --force - don't ask for the page type,
  • --without-register - without automatic registration in the provider,
  • --crud - creates a group of pages: index, detail, and form,
  • --dir= - directory where the files will be located relative to app/MoonShine, defaults to Page,
  • --extends= - class that the page will extend, e.g., IndexPage, FormPage, or DetailPage,
  • --base-dir=, --base-namespace= - change the base directory and namespace of the class.

After executing the command, a default page (or group of pages) will be created in the app/MoonShine/Pages directory.

For more details, refer to the Page section.

Layout

Command to create a layout:

php artisan moonshine:layout
php artisan moonshine:layout

Signature:

moonshine:layout {className?} {--compact} {--full} {--default} {--dir=} {--base-dir=} {--base-namespace=}
moonshine:layout {className?} {--compact} {--full} {--default} {--dir=} {--base-dir=} {--base-namespace=}

Available options:

  • --compact - inherits the compact theme,
  • --full - inherits the base theme,
  • --default - set as the default template in the config,
  • --dir= - directory where the files will be located relative to app/MoonShine, defaults to Layouts,
  • --base-dir=, --base-namespace= - change the base directory and namespace of the class.

For more details, refer to the Layout section.

Component

Command to create a custom component:

php artisan moonshine:component
php artisan moonshine:component

Signature:

moonshine:component {className?} {--base-dir=} {--base-namespace=}
moonshine:component {className?} {--base-dir=} {--base-namespace=}

Available options:

  • --base-dir=, --base-namespace= - change the base directory and namespace of the class.

After executing the command, a class for the component will be created in the app/MoonShine/Components directory, and a Blade file will be created in the resources/views/admin/components directory.

For more details, refer to the Layout section.

Field

Command to create a custom field:

php artisan moonshine:field
php artisan moonshine:field

Signature:

moonshine:field {className?} {--base-dir=} {--base-namespace=}
moonshine:field {className?} {--base-dir=} {--base-namespace=}

Available options:

  • --base-dir=, --base-namespace= - change the base directory and namespace of the class.

When executing the command, you can specify whether the field will extend the base class or another field.

After executing the command, a field class will be created in the app/MoonShine/Fields directory, and a Blade file will be created in the /resources/views/admin/fields directory.

For more details, refer to the Field section.

Command to create a controller:

php artisan moonshine:controller
php artisan moonshine:controller

Signature:

moonshine:controller {className?} {--base-dir=} {--base-namespace=}
moonshine:controller {className?} {--base-dir=} {--base-namespace=}

Available options:

  • --base-dir=, --base-namespace= - change the base directory and namespace of the class.

After executing the command, a controller class will be created in the app/MoonShine/Controllers directory that can be used in the admin panel routes.

For more details, refer to the Controllers section.

Handler

Command to create a Handler class:

php artisan moonshine:handler
php artisan moonshine:handler

Signature:

moonshine:handler {className?} {--base-dir=} {--base-namespace=}
moonshine:handler {className?} {--base-dir=} {--base-namespace=}

Available options:

  • --base-dir=, --base-namespace= - change the base directory and namespace of the class.

After executing the command, a handler class will be created in the app/MoonShine/Handlers directory.

For more details, refer to the Handlers section.

Policy

Command to create a Policy class tied to the admin panel user:

php artisan moonshine:policy
php artisan moonshine:policy

After executing the command, a class will be created in the app/Policies directory.

For more details, refer to the Security > Authorization section.

Type Casting

Command to create a TypeCast class for working with data:

php artisan moonshine:type-cast
php artisan moonshine:type-cast

Signature:

moonshine:type-cast {className?} {--base-dir=} {--base-namespace=}
moonshine:type-cast {className?} {--base-dir=} {--base-namespace=}

Available options:

  • --base-dir=, --base-namespace= - change the base directory and namespace of the class.

After executing the command, a file will be created in the app/MoonShine/TypeCasts directory.

For more details, refer to the TypeCasts section.

Publishing

Command for publishing:

php artisan moonshine:publish
php artisan moonshine:publish

Several options are available for publishing:

  • Assets - assets for the MoonShine admin panel,
  • Assets template - creates a template for adding custom styles or creating a custom theme for MoonShine,
  • System Resources - system MoonShineUserResource, MoonShineUserRoleResource, which you can modify,
  • System Forms - system LoginForm, FiltersForm, which you can modify,
  • System Pages - system ProfilePage, LoginPage, ErrorPage, which you can modify.

You can specify the publication type directly in the command.

php artisan moonshine:publish assets
php artisan moonshine:publish assets

Available types:

  • assets
  • assets-template
  • resources
  • forms
  • pages

Apply

Command to create an apply class:

php artisan moonshine:apply
php artisan moonshine:apply

Signature:

moonshine:apply {className?} {--base-dir=} {--base-namespace=}
moonshine:apply {className?} {--base-dir=} {--base-namespace=}

Available options:

  • --base-dir=, --base-namespace= - change the base directory and namespace of the class.

After executing the command, a file will be created in the app/MoonShine/Applies directory. The created class needs to be registered in the service provider.

For more details, refer to the Fields section.