laravel-admin 树状列表

namespace App\Admin\Controllers;

use App\Model\AddressModel;
use App\Model\ArticleModel;
use App\Model\ArticleTypeModel;
use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Facades\Admin;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Layout\Content;
use Encore\Admin\Show;

class ArticleTypeController extends AdminController
{
    /**
     * Title for current resource.
     *
     * @var string
     */
    protected $title = '新闻分类';

    public function index(Content $content)
    {
        return Admin::content(function (Content $content) {
            $content->header($this->title);
            $content->body(ArticleTypeModel::tree(function ($tree) {
                $tree->branch(function ($branch) {
                    return "{$branch['sort_order']} - {$branch['typename']}";
                });
            }));
        });
    }
}
Model操作

namespace App\Model;

use Encore\Admin\Traits\AdminBuilder;
use Encore\Admin\Traits\ModelTree;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Http\Request;

class ArticleTypeModel extends Model
{
    use ModelTree,AdminBuilder;
    protected $fillable =['parent_id','typename','sort_order'];
    public function __construct(array $attributes = [])
    {
        parent::__construct($attributes);
        $this->setParentColumn('parent_id');
        $this->setOrderColumn('sort_order');
        $this->setTitleColumn('typename');
    }

    //
    protected $table = "article_type";
    protected $primaryKey = 'arttype_id';

 laravel-admin 树状列表_第1张图片

你可能感兴趣的:(laravel)