主頁 > 知識庫 > laravel admin實現(xiàn)分類樹/模型樹的示例代碼

laravel admin實現(xiàn)分類樹/模型樹的示例代碼

熱門標簽:科大訊飛語音識別系統(tǒng) 團購網(wǎng)站 銀行業(yè)務 電子圍欄 服務器配置 Linux服務器 阿里云 Mysql連接數(shù)設置

修改模型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 = '商品分類管理';

 public function index(Content $content)
 {
  return Admin::content(function ($content) {
   $content->header('商品分類管理');
   $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中使用分類樹

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

總結

到此這篇關于laravel admin實現(xiàn)分類樹/模型樹的示例代碼的文章就介紹到這了,更多相關laravel admin 分類樹 模型樹內容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!

您可能感興趣的文章:
  • laravel5.6 框架操作數(shù)據(jù) Eloquent ORM用法示例
  • Laravel 手動開關 Eloquent 修改器的操作方法
  • laravel框架數(shù)據(jù)庫操作、查詢構建器、Eloquent ORM操作實例分析
  • Laravel框架Eloquent ORM新增數(shù)據(jù)、自定義時間戳及批量賦值用法詳解
  • Laravel框架Eloquent ORM簡介、模型建立及查詢數(shù)據(jù)操作詳解
  • Laravel框架Eloquent ORM修改數(shù)據(jù)操作示例
  • Laravel Eloquent分表方法并使用模型關聯(lián)的實現(xiàn)
  • laravel7學習之無限級分類的最新實現(xiàn)方法
  • 如何使用Laravel Eloquent來開發(fā)無限極分類

標簽:大理 廣元 蚌埠 江蘇 棗莊 衢州 衡水 萍鄉(xiāng)

巨人網(wǎng)絡通訊聲明:本文標題《laravel admin實現(xiàn)分類樹/模型樹的示例代碼》,本文關鍵詞  ;如發(fā)現(xiàn)本文內容存在版權問題,煩請?zhí)峁┫嚓P信息告之我們,我們將及時溝通與處理。本站內容系統(tǒng)采集于網(wǎng)絡,涉及言論、版權與本站無關。
  • 相關文章
  • 收縮
    • 微信客服
    • 微信二維碼
    • 電話咨詢

    • 400-1100-266