日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > php >内容正文

php

smartadmin的php配置本,laravel-admin自动生成模块,及相关基础配置方法

發布時間:2023/12/10 php 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 smartadmin的php配置本,laravel-admin自动生成模块,及相关基础配置方法 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

一、模型創建、數據遷移、以及關聯模型控制器

$ php artisan make:model Brand -m  //創建模型并生成遷移文件

$ php artisan migrate  //運行遷移

$ php artisan admin:make BrandController --model=App\Brand  //創建關聯Brand模型的控制器

二、問題:創建模型后,會生成一個臨時文件(php artisan make:model Brand -m)

路徑:database/migrations/2018_10_16_0000_create_模型名s_table.php

在up方法中加入數據表應有的字段,例如:

$table->text('content');

可用的字段類型

數據庫結構生成器包含構建表時可以指定的各種字段類型:

命令

描述

$table->bigIncrements('id');

遞增 ID(主鍵),相當于「UNSIGNED BIG INTEGER」

$table->bigInteger('votes');

相當于 BIGINT

$table->binary('data');

相當于 BLOB

$table->boolean('confirmed');

相當于 BOOLEAN

$table->char('name', 4);

相當于帶有長度的 CHAR

$table->date('created_at');

相當于 DATE

$table->dateTime('created_at');

相當于 DATETIME

$table->dateTimeTz('created_at');

相當于帶時區 DATETIME

$table->decimal('amount', 8, 2);

相當于帶有精度與基數 DECIMAL

$table->double('column', 8, 2);

相當于帶有精度與基數 DOUBLE

$table->enum('level', ['easy', 'hard']);

相當于 ENUM

$table->float('amount', 8, 2);

相當于帶有精度與基數 FLOAT

$table->geometry('positions');

相當于 GEOMETRY

$table->geometryCollection('positions');

相當于 GEOMETRYCOLLECTION

$table->increments('id');

遞增的 ID (主鍵),相當于「UNSIGNED INTEGER」

$table->integer('votes');

相當于 INTEGER

$table->ipAddress('visitor');

相當于 IP 地址

$table->json('options');

相當于 JSON

$table->jsonb('options');

相當于 JSONB

$table->lineString('positions');

相當于 LINESTRING

$table->longText('description');

相當于 LONGTEXT

$table->macAddress('device');

相當于 MAC 地址

$table->mediumIncrements('id');

遞增 ID (主鍵) ,相當于「UNSIGNED MEDIUM INTEGER」

$table->mediumInteger('votes');

相當于 MEDIUMINT

$table->mediumText('description');

相當于 MEDIUMTEXT

$table->morphs('taggable');

相當于加入遞增的 taggable_id 與字符串 taggable_type

$table->multiLineString('positions');

相當于 MULTILINESTRING

$table->multiPoint('positions');

相當于 MULTIPOINT

$table->multiPolygon('positions');

相當于 MULTIPOLYGON

$table->nullableMorphs('taggable');

相當于可空版本的 morphs() 字段

$table->nullableTimestamps();

相當于可空版本的 timestamps() 字段

$table->point('position');

相當于 POINT

$table->polygon('positions');

相當于 POLYGON

$table->rememberToken();

相當于可空版本的 VARCHAR(100) 的 remember_token 字段

$table->smallIncrements('id');

遞增 ID (主鍵) ,相當于「UNSIGNED SMALL INTEGER」

$table->smallInteger('votes');

相當于 SMALLINT

$table->softDeletes();

相當于為軟刪除添加一個可空的 deleted_at 字段

$table->softDeletesTz();

相當于為軟刪除添加一個可空的 帶時區的 deleted_at 字段

$table->string('name', 100);

相當于帶長度的 VARCHAR

$table->text('description');

相當于 TEXT

$table->time('sunrise');

相當于 TIME

$table->timeTz('sunrise');

相當于帶時區的 TIME

$table->timestamp('added_on');

相當于 TIMESTAMP

$table->timestampTz('added_on');

相當于帶時區的 TIMESTAMP

$table->tinyIncrements('id');

相當于自動遞增 UNSIGNED TINYINT

$table->tinyInteger('votes');

相當于 TINYINT

$table->unsignedBigInteger('votes');

相當于 Unsigned BIGINT

$table->unsignedDecimal('amount', 8, 2);

相當于帶有精度和基數的 UNSIGNED DECIMAL

$table->unsignedInteger('votes');

相當于 Unsigned INT

$table->unsignedMediumInteger('votes');

相當于 Unsigned MEDIUMINT

$table->unsignedSmallInteger('votes');

相當于 Unsigned SMALLINT

$table->unsignedTinyInteger('votes');

相當于 Unsigned TINYINT

$table->uuid('id');

相當于 UUID

$table->year('birth_year');

相當于 YEAR

三、然后運行遷移和創建關聯的控制器

$ php artisan migrate  //運行遷移

$ php artisan admin:make BrandController --model=App\Brand  //創建關聯Brand模型的控制器

四、如果數據庫表結構需要修改

如二步驟,修改完成,刪除migrations表中相關的那條記錄,并且刪除相關表

再次運行遷移,此方法適用于無數據的表,已有數據庫的表,請不要操作

$ php artisan migrate  //運行遷移

五、新創建的后臺模塊與后臺自帶的模塊不一樣

新創建:

后他自帶:

如果想改成后臺自帶這種樣式的,就必須得調用系統自帶的方法,如下:

1,先在需要添加的控制器中引入這些類:

use Encore\Admin\Show;

use Encore\Admin\Tree;

use Encore\Admin\Layout\Row;

use Encore\Admin\Widgets\Box;

use Encore\Admin\Facades\Admin;

use Encore\Admin\Layout\Column;

2,并且在index方法中,所有的替換成如下代碼:

return Admin::content(function (Content $content) {

$content->header('Index');

$content->description('description');

$content->row(function (Row $row) {

$row->column(6, $this->treeView()->render());

$row->column(6, function (Column $column) {

$form = new \Encore\Admin\Widgets\Form();

$form->action(admin_base_path('/cate控制器名'));//控制器名

$form->select('fid','父級欄目')->options(Cate控制器名::selectOptions());//控制器名

$form->text('name','欄目名稱')->rules('required');//其他form根據情況自行修改

$form->text('sort','排序')->rules('required');

$form->text('jump_to','跳轉')->rules('required');;

$form->hidden('_token')->default(csrf_token());

$column->append((new Box(trans('admin.new'), $form))->style('success'));

});

});

});

3,而且要在此控制器中添加如下方法:

/**

* Make a treeView()

*

* @return tree

*/

protected function treeView()

{

return Cate控制器名::tree(function (Tree $tree) {

$tree->disableCreate();

return $tree;

});

}

4,在相關的model中添加如下方法和引用類:

//引用這兩個類

use Encore\Admin\Traits\AdminBuilder;

use Encore\Admin\Traits\ModelTree;

//并且添加這個方法

use ModelTree, AdminBuilder;

//字段自行修改

protected $fillable = ['name','sort','fid','jump_to'];

public function __construct(array $attributes = [])

{

parent::__construct($attributes);

$this->setParentColumn('fid');

$this->setOrderColumn('sort');

$this->setTitleColumn('name');

}

以上這篇laravel-admin自動生成模塊,及相關基礎配置方法就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持腳本之家。

總結

以上是生活随笔為你收集整理的smartadmin的php配置本,laravel-admin自动生成模块,及相关基础配置方法的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。