欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

laravel-admin自動(dòng)生成模塊,及相關(guān)基礎(chǔ)配置方法

 更新時(shí)間:2019年10月08日 14:56:55   作者:qq_36100763  
今天小編就為大家分享一篇laravel-admin自動(dòng)生成模塊,及相關(guān)基礎(chǔ)配置方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧

一、模型創(chuàng)建、數(shù)據(jù)遷移、以及關(guān)聯(lián)模型控制器

$ php artisan make:model Brand -m  //創(chuàng)建模型并生成遷移文件
 
$ php artisan migrate  //運(yùn)行遷移
 
$ php artisan admin:make BrandController --model=App\Brand  //創(chuàng)建關(guān)聯(lián)Brand模型的控制器

二、問(wèn)題:創(chuàng)建模型后,會(huì)生成一個(gè)臨時(shí)文件(php artisan make:model Brand -m)

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

在up方法中加入數(shù)據(jù)表應(yīng)有的字段,例如:

$table->text('content');

可用的字段類型

數(shù)據(jù)庫(kù)結(jié)構(gòu)生成器包含構(gòu)建表時(shí)可以指定的各種字段類型:

命令 描述
$table->bigIncrements('id'); 遞增 ID(主鍵),相當(dāng)于「UNSIGNED BIG INTEGER」
$table->bigInteger('votes'); 相當(dāng)于 BIGINT
$table->binary('data'); 相當(dāng)于 BLOB
$table->boolean('confirmed'); 相當(dāng)于 BOOLEAN
$table->char('name', 4); 相當(dāng)于帶有長(zhǎng)度的 CHAR
$table->date('created_at'); 相當(dāng)于 DATE
$table->dateTime('created_at'); 相當(dāng)于 DATETIME
$table->dateTimeTz('created_at'); 相當(dāng)于帶時(shí)區(qū) DATETIME
$table->decimal('amount', 8, 2); 相當(dāng)于帶有精度與基數(shù) DECIMAL
$table->double('column', 8, 2); 相當(dāng)于帶有精度與基數(shù) DOUBLE
$table->enum('level', ['easy', 'hard']); 相當(dāng)于 ENUM
$table->float('amount', 8, 2); 相當(dāng)于帶有精度與基數(shù) FLOAT
$table->geometry('positions'); 相當(dāng)于 GEOMETRY
$table->geometryCollection('positions'); 相當(dāng)于 GEOMETRYCOLLECTION
$table->increments('id'); 遞增的 ID (主鍵),相當(dāng)于「UNSIGNED INTEGER」
$table->integer('votes'); 相當(dāng)于 INTEGER
$table->ipAddress('visitor'); 相當(dāng)于 IP 地址
$table->json('options'); 相當(dāng)于 JSON
$table->jsonb('options'); 相當(dāng)于 JSONB
$table->lineString('positions'); 相當(dāng)于 LINESTRING
$table->longText('description'); 相當(dāng)于 LONGTEXT
$table->macAddress('device'); 相當(dāng)于 MAC 地址
$table->mediumIncrements('id'); 遞增 ID (主鍵) ,相當(dāng)于「UNSIGNED MEDIUM INTEGER」
$table->mediumInteger('votes'); 相當(dāng)于 MEDIUMINT
$table->mediumText('description'); 相當(dāng)于 MEDIUMTEXT
$table->morphs('taggable'); 相當(dāng)于加入遞增的 taggable_id 與字符串 taggable_type
$table->multiLineString('positions'); 相當(dāng)于 MULTILINESTRING
$table->multiPoint('positions'); 相當(dāng)于 MULTIPOINT
$table->multiPolygon('positions'); 相當(dāng)于 MULTIPOLYGON
$table->nullableMorphs('taggable'); 相當(dāng)于可空版本的 morphs() 字段
$table->nullableTimestamps(); 相當(dāng)于可空版本的 timestamps() 字段
$table->point('position'); 相當(dāng)于 POINT
$table->polygon('positions'); 相當(dāng)于 POLYGON
$table->rememberToken(); 相當(dāng)于可空版本的 VARCHAR(100) 的 remember_token 字段
$table->smallIncrements('id'); 遞增 ID (主鍵) ,相當(dāng)于「UNSIGNED SMALL INTEGER」
$table->smallInteger('votes'); 相當(dāng)于 SMALLINT
$table->softDeletes(); 相當(dāng)于為軟刪除添加一個(gè)可空的 deleted_at 字段
$table->softDeletesTz(); 相當(dāng)于為軟刪除添加一個(gè)可空的 帶時(shí)區(qū)的 deleted_at 字段
$table->string('name', 100); 相當(dāng)于帶長(zhǎng)度的 VARCHAR
$table->text('description'); 相當(dāng)于 TEXT
$table->time('sunrise'); 相當(dāng)于 TIME
$table->timeTz('sunrise'); 相當(dāng)于帶時(shí)區(qū)的 TIME
$table->timestamp('added_on'); 相當(dāng)于 TIMESTAMP
$table->timestampTz('added_on'); 相當(dāng)于帶時(shí)區(qū)的 TIMESTAMP
$table->tinyIncrements('id'); 相當(dāng)于自動(dòng)遞增 UNSIGNED TINYINT
$table->tinyInteger('votes'); 相當(dāng)于 TINYINT
$table->unsignedBigInteger('votes'); 相當(dāng)于 Unsigned BIGINT
$table->unsignedDecimal('amount', 8, 2); 相當(dāng)于帶有精度和基數(shù)的 UNSIGNED DECIMAL
$table->unsignedInteger('votes'); 相當(dāng)于 Unsigned INT
$table->unsignedMediumInteger('votes'); 相當(dāng)于 Unsigned MEDIUMINT
$table->unsignedSmallInteger('votes'); 相當(dāng)于 Unsigned SMALLINT
$table->unsignedTinyInteger('votes'); 相當(dāng)于 Unsigned TINYINT
$table->uuid('id'); 相當(dāng)于 UUID
$table->year('birth_year'); 相當(dāng)于 YEAR

三、然后運(yùn)行遷移和創(chuàng)建關(guān)聯(lián)的控制器

$ php artisan migrate  //運(yùn)行遷移

$ php artisan admin:make BrandController --model=App\Brand  //創(chuàng)建關(guān)聯(lián)Brand模型的控制器

四、如果數(shù)據(jù)庫(kù)表結(jié)構(gòu)需要修改

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

再次運(yùn)行遷移,此方法適用于無(wú)數(shù)據(jù)的表,已有數(shù)據(jù)庫(kù)的表,請(qǐng)不要操作

$ php artisan migrate  //運(yùn)行遷移

五、新創(chuàng)建的后臺(tái)模塊與后臺(tái)自帶的模塊不一樣

新創(chuàng)建:

后他自帶:

如果想改成后臺(tái)自帶這種樣式的,就必須得調(diào)用系統(tǒng)自帶的方法,如下:

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','父級(jí)欄目')->options(Cate控制器名::selectOptions());//控制器名
     $form->text('name','欄目名稱')->rules('required');//其他form根據(jù)情況自行修改
     $form->text('sort','排序')->rules('required');
     $form->text('jump_to','跳轉(zhuǎn)')->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,在相關(guān)的model中添加如下方法和引用類:

//引用這兩個(gè)類
use Encore\Admin\Traits\AdminBuilder;
use Encore\Admin\Traits\ModelTree;
//并且添加這個(gè)方法
 
 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自動(dòng)生成模塊,及相關(guān)基礎(chǔ)配置方法就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論