Fields

You're browsing the documentation for an old version of MoonShine. Consider upgrading your project to MoonShine 2.x.

Fields in most cases refer to table fields from the database. Within CRUD they will be displayed with a list on the main page of the section (resource) and on the page for creating and editing records. There are many types of fields in the MoonShine admin panel to cover all possible requirements! They also cover all possible relationships in Laravel and are named in the same way as relationship methods for convenience: BelongsTo, BelongsToMany, HasOne, HasMany, HasOneThrough, HasManyThrough, MorphOne, MorphMany

Adding new fields is extremely easy! You can simply return all the required fields in the fields method which returns an array. And we will talk about fields structure in the "Fields" section.

namespace MoonShine\Resources;
 
use MoonShine\Models\MoonshineUser;
use MoonShine\Fields\ID;
use MoonShine\Fields\Text;
use MoonShine\Decorations\Block;
 
class PostResource extends Resource
{
public static string $model = App\Models\Post::class;
 
public static string $title = 'Articles';
//...
 
public function fields(): array
{
return [
Block::make('Block title', [
ID::make(),
Text::make('header', 'title'),
])
];
}
 
//...
}