生成模型和迁移文件
?
|
1
|
php artisan make:model Models/Shoping/Category -m
|
app/Models/Shoping/Category.php
?
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
<?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");
}
}
|
迁移文件
?
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
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');
}
}
|
生成控制器
?
|
1
|
php artisan admin:make CategoriesController --model=App\\Models\\Shoping\\Category
|
app/Admin/Controllers/CategoriesController.php
?
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
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', '排序序号')->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
?
|
1
|
$router->resource('categories',CategoryController::class);
|
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持快网idc。
原文链接:https://segmentfault.com/a/1190000021613850
相关文章
猜你喜欢
- ASP.NET自助建站系统中的用户注册和登录功能定制方法 2025-06-10
- ASP.NET自助建站系统的域名绑定与解析教程 2025-06-10
- 个人服务器网站搭建:如何选择合适的服务器提供商? 2025-06-10
- ASP.NET自助建站系统中如何实现多语言支持? 2025-06-10
- 64M VPS建站:如何选择最适合的网站建设平台? 2025-06-10
TA的动态
- 2025-07-10 怎样使用阿里云的安全工具进行服务器漏洞扫描和修复?
- 2025-07-10 怎样使用命令行工具优化Linux云服务器的Ping性能?
- 2025-07-10 怎样使用Xshell连接华为云服务器,实现高效远程管理?
- 2025-07-10 怎样利用云服务器D盘搭建稳定、高效的网站托管环境?
- 2025-07-10 怎样使用阿里云的安全组功能来增强服务器防火墙的安全性?
快网idc优惠网
QQ交流群
您的支持,是我们最大的动力!
热门文章
-
2025-06-04 56
-
容器化技术(如Docker和Kubernetes)在现代网站部署中的应用
2025-06-04 65 -
2025-05-25 98
-
2025-06-04 73
-
2025-05-27 102
热门评论

