laravel admin - xiaogardenz/Work GitHub Wiki

创建模型

php artisan make:model Brand -m  //创建模型并生成迁移文件
php artisan migrate  //运行迁移
//win
php artisan admin:make BrandController --model=App\Brand  //创建关联Brand模型的控制器
//linux
php artisan admin:make BrandController --model=App\\Brand  //创建关联Brand模型的控制器

模型自定义表

protected $table = "product";

时间戳格式化

const CREATED_AT = 'create_time';
const UPDATED_AT = 'update_time';
public function getCreateTimeAttribute() {

		return $this->getTimeType( 'create_time' );
	}

	public function getUpdateTimeAttribute() {
		return $this->getTimeType( 'update_time' );
	}

	public function setCreateTimeAttribute( $value ) {
		$this->attributes['create_time'] = strtotime( $value );
	}

	public function setUpdateTimeAttribute( $value ) {
		$this->attributes['update_time'] = strtotime( $value );
	}

	protected function getTimeType( string $time_type ) {
		if ( $this->attributes[ $time_type ] ) {
			$time_info = date( 'Y-m-d H:i:s', $this->attributes[ $time_type ] );
		} else {
			$time_info = '--';
		}

		return $time_info;
	}

富文本编辑器

1: git clone https://github.com/laravel/laravel.git (安装laravel)
2: composer require yxx/kindeditor (安装富文本编辑器拓展)
3: 如果没有安装laravel-admin,参考一下网址操作 -laravel-admin
4: 运行 php artisan vendor:publish --provider="Yxx\Kindeditor\EditorProvider"
5: php artisan storage:link 建立软连接

上传图片注意,需要建立软链接

php artisan storage:link