z-song / laravel-admin

Build a full-featured administrative interface in ten minutes
https://laravel-admin.org
MIT License
11.14k stars 2.81k forks source link

how to add the grid in to the dashboard? #5821

Closed jesnagifto closed 1 year ago

jesnagifto commented 1 year ago

Description:

how to add the grid in to the dashboard? please help me fast.

Steps To Reproduce:

axsweet commented 1 year ago

This is not really a great question...

On Fri, Sep 15, 2023 at 12:31 AM jesnagifto @.***> wrote:

  • Laravel Version: #.#.#
  • PHP Version:
  • Laravel-admin: #.#.#

Description:

how to add the grid in to the dashboard? please help me fast. Steps To Reproduce:

— Reply to this email directly, view it on GitHub https://github.com/z-song/laravel-admin/issues/5821, or unsubscribe https://github.com/notifications/unsubscribe-auth/ALF5SJGFS6U3NZNDTOT4Q73X2PK3NANCNFSM6AAAAAA4ZHEDQM . You are receiving this because you are subscribed to this thread.Message ID: @.***>

alexoleynik0 commented 1 year ago

If you open the \Encore\Admin\Controllers\AdminController that every model-related controller uses, you will see that it has index method and how it uses the \Encore\Admin\Layout\Content and your grid method to display content.

You can learn about Layout more here.

But basically you need something like this:

<?php

namespace App\Admin\Controllers;

use App\Admin\Models\User;
use App\Http\Controllers\Controller;
use Encore\Admin\Grid;
use Encore\Admin\Layout\Content;

class HomeController extends Controller
{
    public function index(Content $content)
    {
        return $content
            ->title('Dashboard')
            ->row($this->grid())
        ;
    }

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        $model = new User();
        $grid = new Grid($model);

        $grid->setResource(route(admin_get_route('users.index')));

        $grid->column('id', __('Id'));
        $grid->column('name', __('Name human'))->sortable()->editable();
        $grid->column('email', __('Email'))->sortable()->copyable();
        $grid->column('created_at', __('Created at'))->sortable();

        return $grid;
    }
}
jesnagifto commented 1 year ago

thank you very much