Dashboard

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

# Basics

The home page of the admin panel can be customized through the class app/MoonShine/Dashboard.php.

Currently you can display metrics in the control panel

The required metrics are registered in the blocks method and placed in the DashboardBlock wrapper for a convenient arrangement of the panel

Layout (columnSpan) decorating methods are also available for the elements

namespace App\MoonShine;
 
use App\Models\User;
use MoonShine\Dashboard\DashboardBlock;
use MoonShine\Dashboard\DashboardScreen;
use MoonShine\Metrics\ValueMetric;
 
class Dashboard extends DashboardScreen
{
public function blocks(): array
{
return [
DashboardBlock::make([
ValueMetric::make('Users')
->value(User::query()->count())
])
];
}
}

# Block with resource records

Sometimes it is extremely convenient to add a table with records from a resource to the main page for quick access. To do this, use ResourcePreview

namespace App\MoonShine;
 
use App\Models\Article;
use MoonShine\Dashboard\DashboardBlock;
use MoonShine\Dashboard\DashboardScreen;
use MoonShine\Dashboard\ResourcePreview;
 
class Dashboard extends DashboardScreen
{
public function blocks(): array
{
return [
DashboardBlock::make([
ResourcePreview::make(
new ArticleResource(), // Mandatory parameter with MoonShine resource
'Latest articles', // Optional - block header
Article::query()->where('active', true)->limit(2) // Optional QueryBuilder
)
])
];
}
}

# Text block

To display plain text

namespace App\MoonShine;
 
use MoonShine\Dashboard\DashboardBlock;
use MoonShine\Dashboard\DashboardScreen;Welcome
use MoonShine\Dashboard\TextBlock;
 
class Dashboard extends DashboardScreen
{
public function blocks(): array
{
return [
DashboardBlock::make([
TextBlock::make(
'Welcome',
view('welcome')->render()
)
])
];
}
}