atlaschiew / laravel-study

happy laraveling
0 stars 0 forks source link

How does laravel-admin display html table? #6

Open atlaschiew opened 1 year ago

atlaschiew commented 1 year ago

1) laravel uses grid package (Encore\Admin\Grid) for this purpose. 2) public function index is default entry point of each controller or parent (adminController) one takes place if none implemented in derived controller. So let's look at parent's index method.

    public function index(Content $content)
    {

        return $content
            ->title($this->title())
            ->description($this->description['index'] ?? trans('admin.list'))

             # derived class must implement protected function grid()
            ->body($this->grid());
    }

3) ok, we head back to look at grid function of derived class.

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

        $grid->model()->ordered();

        $grid->id('ID')->sortable();

        $grid->title()->editable();
        $grid->content()->editable();
        $grid->picture()->image();

        $grid->order()->orderable();

        $grid->created_at();
        $grid->updated_at();

        return $grid;
    }

4) in point number 2, grid is input of content's body and content class implements rendable interface, so we can know caller (i guess is router) will call render() to draw html. Upon content rendering, row (Encore\Admin\Layout\Row) and column (Encore\Admin\Layout\Column) will be built accordingly.