Laraveladmin實(shí)現(xiàn)分類(lèi)樹(shù)/模型樹(shù)的示例

這篇文章將為大家詳細(xì)講解有關(guān)Laravel admin實(shí)現(xiàn)分類(lèi)樹(shù)/模型樹(shù)的示例,小編覺(jué)得挺實(shí)用的,因此分享給大家做個(gè)參考,希望大家閱讀完這篇文章后可以有所收獲。

創(chuàng)新互聯(lián)建站網(wǎng)站建設(shè)公司是一家服務(wù)多年做網(wǎng)站建設(shè)策劃設(shè)計(jì)制作的公司,為廣大用戶(hù)提供了成都網(wǎng)站建設(shè)、網(wǎng)站建設(shè),成都網(wǎng)站設(shè)計(jì),1元廣告,成都做網(wǎng)站選創(chuàng)新互聯(lián)建站,貼合企業(yè)需求,高性?xún)r(jià)比,滿(mǎn)足客戶(hù)不同層次的需求一站式服務(wù)歡迎致電。

修改模型Category.php

<?php

namespace App\Admin\Models;

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

class Category extends Model
{
 use ModelTree, AdminBuilder;

 protected $table = 'category';

 public function __construct(array $attributes = [])
 {
  parent::__construct($attributes);
		//這里根據(jù)自己的字段修改
  $this->setParentColumn('parent_id');
  $this->setOrderColumn('sort');
  $this->setTitleColumn('name');
 }
 }

修改控制文件CategoryController.php

<?php

namespace App\Admin\Controllers;

use App\Admin\Models\Category;
use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Facades\Admin;
use Encore\Admin\Layout\Content;
use Encore\Admin\Show;

class CategoryController extends AdminController
{
 /**
  * Title for current resource.
  *
  * @var string
  */
 protected $title = '商品分類(lèi)管理';

 public function index(Content $content)
 {
  return Admin::content(function ($content) {
   $content->header('商品分類(lèi)管理');
   $content->body(Category::tree(function ($tree) {
    $tree->branch(function ($branch) {
     $src = config('admin.upload.host') . '/' . $branch['image'];
     $logo = "<img src='$src' style='max-width:30px;max-height:30px' class='img'/>";

     return "{$branch['id']} - {$branch['name']} $logo";
    });
   }));
  });
 }
	//下面是自己的代碼
	//.......
 }

添加路由app/Admin/routes.php

$router->resource('categories',CategoryController::class);

select中使用分類(lèi)樹(shù)

$form->select('parent_id', __('Parent id'))->options(Category::selectOptions())->default(1);

關(guān)于“Laravel admin實(shí)現(xiàn)分類(lèi)樹(shù)/模型樹(shù)的示例”這篇文章就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,使各位可以學(xué)到更多知識(shí),如果覺(jué)得文章不錯(cuò),請(qǐng)把它分享出去讓更多的人看到。

名稱(chēng)欄目:Laraveladmin實(shí)現(xiàn)分類(lèi)樹(shù)/模型樹(shù)的示例
標(biāo)題路徑:http://muchs.cn/article44/jcjche.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供品牌網(wǎng)站建設(shè)、網(wǎng)站制作、外貿(mào)建站、外貿(mào)網(wǎng)站建設(shè)、用戶(hù)體驗(yàn)、域名注冊(cè)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶(hù)投稿、用戶(hù)轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀(guān)點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話(huà):028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

成都做網(wǎng)站