laravel-admin利用ModelTree實(shí)現(xiàn)對(duì)分類信息的管理
生成模型和遷移文件
php artisan make:model Models/Shoping/Category -m
app/Models/Shoping/Category.php
<?php namespace App\Models\Shoping; use Encore\Admin\Traits\AdminBuilder; use Encore\Admin\Traits\ModelTree; use Illuminate\Database\Eloquent\Model; /** * * Class Category * @package App\Models\Shoping */ class Category extends Model { // use ModelTree, AdminBuilder; protected $table="shoping_categories"; public function __construct(array $attributes = []) { parent::__construct($attributes); $this->setTitleColumn("name"); } }
遷移文件
class CreateCategoriesTable extends Migration { /** * Run the migrations. * * @return void */ public function up() { Schema::create('shoping_categories', function (Blueprint $table) { $table->increments('id'); $table->integer('parent_id')->unsigned()->nullable(); $table->string('name'); $table->string('description')->nullable(); $table->integer('order')->unsigned(); $table->timestamps(); }); } /** * Reverse the migrations. * * @return void */ public function down() { Schema::dropIfExists('shoping_categories'); } }
生成控制器
php artisan admin:make CategoriesController --model=App\Models\Shoping\Category
app/Admin/Controllers/CategoriesController.php
use App\Models\Shoping\Category; use Encore\Admin\Controllers\AdminController; use Encore\Admin\Form; use Encore\Admin\Grid; use Encore\Admin\Layout\Column; use Encore\Admin\Layout\Content; use Encore\Admin\Layout\Row; use Encore\Admin\Show; use Encore\Admin\Tree; use Encore\Admin\Widgets\Box; class CategoriesController extends AdminController { public function index(Content $content) { return $content->title($this->title) ->description("分類列表") ->row(function (Row $row) { $row->column(6, $this->treeView()->render()); $row->column(6, function (Column $column) { $form = new Form(); $form->select('parent_id', "父類名稱")->options(Category::selectOptions()); $form->text('name', __('Name')); $form->text('description', __('Description')); $form->number('order', '排序序號(hào)')->default(0); $column->append((new Box(trans('admin.new'), $form))->style('success')); }); }); } protected function treeView() { return Category::tree(function (Tree $tree) { $tree->disableCreate(); return $tree; }); }
添加路由
app/admin/routes.php
$router->resource('categories',CategoryController::class);
以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
深入剖析瀏覽器退出之后php還會(huì)繼續(xù)執(zhí)行么
覽器退出之后php還會(huì)繼續(xù)執(zhí)行么?下面小編就為大家介紹一下究竟覽器退出之后php還會(huì)不會(huì)繼續(xù)執(zhí)行。一起跟隨小編過來看看吧2016-05-05PHP連接SQL Server的方法分析【基于thinkPHP5.1框架】
這篇文章主要介紹了PHP連接SQL Server的方法,結(jié)合實(shí)例形式分析了基于thinkPHP5.1框架Db類以及使用PDO進(jìn)行SQL Server數(shù)據(jù)庫連接的相關(guān)操作實(shí)現(xiàn)技巧,需要的朋友可以參考下2019-05-05PHP的MVC模式實(shí)現(xiàn)原理分析(一相簡單的MVC框架范例)
PHP的mvc框架很多,像Yii,CodeIgniter,ThinkPHP等現(xiàn)在流行的框架,利用MVC模式進(jìn)行web頁面的開發(fā),我們可以非常方便的編寫web程序2014-04-04laravel框架上傳圖片實(shí)現(xiàn)實(shí)時(shí)預(yù)覽功能
今天小編就為大家分享一篇laravel框架上傳圖片實(shí)現(xiàn)實(shí)時(shí)預(yù)覽功能,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2019-10-10PHP 進(jìn)程池與輪詢調(diào)度算法實(shí)現(xiàn)多任務(wù)的示例代碼
這篇文章主要介紹了PHP 進(jìn)程池與輪詢調(diào)度算法實(shí)現(xiàn)多任務(wù)的示例代碼,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-11-11php模仿qq空間或朋友圈發(fā)布動(dòng)態(tài)、評(píng)論動(dòng)態(tài)、回復(fù)評(píng)論、刪除動(dòng)態(tài)或評(píng)論的功能(中)
這篇文章主要介紹了模仿qq空間或朋友圈發(fā)布動(dòng)態(tài)、評(píng)論動(dòng)態(tài)、回復(fù)評(píng)論、刪除動(dòng)態(tài)或評(píng)論的功能(中) ,需要的朋友可以參考下2017-06-06