composer create-project laravel/laravel=5.5 blog_wangeditor --prefer-dist
vim .env
composer require "caouecs/laravel-lang:~3.0"
安装之后将语言包移动到对应位置就好了,语言包默认位置是resources/lang
cp -a vendor/caouecs/laravel-lang/src/zh-CN resources/lang
修改config/app.php
将local的值改为zh-CN
laravel-admin
composer 安装
composer require encore/laravel-admin "1.3.*"
在config/app.php
加入ServiceProvider:
Encore\Admin\Providers\AdminServiceProvider::class
发布资源
php artisan vendor:publish --tag=laravel-admin
安装
php artisan admin:install
php artisan make:auth
执行迁移
php artisan migrate
php artisan make:migration create_posts_table --create=posts
database/2018_01_14_191442_create_posts_table.php
public function up()
{
Schema::create('posts', function (Blueprint $table) {
$table->increments('id');
$table->text('title');
$table->text('subtitle');
$table->text('cover');
$table->enum('type', ['0', '1', '2', '3', '4', '5', '9'])->default('0');
$table->text('content');
$table->timestamps();
});
}
php artisan migrate
模型
php artisan make:model App\\Models\\Post
控制器
php artisan admin:make PostController --model=App\\Models\\Post
Admin/routes.php
$router->resource('/post', 'PostController');
app/Admin/PostController.php
里面的form和grid两个方法 protected function grid()
{
return Admin::grid(Post::class, function (Grid $grid) {
$grid->id('ID')->sortable();
$grid->title('标题');
$grid->subtitle('副标题');
$grid->type('类型')->options([
'0' => 'php',
'1' => 'laravel',
'2' => 'javascript',
'3' => 'python',
'4' => 'golang',
'5' => 'linux',
'9' => 'other'
]);
$grid->cover('封面')->image('/uploads', 100, 100);
$grid->content('内容')->limit(100);
$grid->created_at('创建时间');
$grid->updated_at('修改时间');
});
}
protected function form()
{
return Admin::form(Post::class, function (Form $form) {
$form->display('id', 'ID');
$form->text('title', '标题');
$form->textarea('subtitle', '副标题')->rows(3);
$form->select('type', '类型')->options([
'0' => 'php',
'1' => 'laravel',
'2' => 'javascript',
'3' => 'python',
'4' => 'golang',
'5' => 'linux',
'9' => 'other'
]);
$form->image('cover', '封面');
$form->editor('content', '内容');
$form->display('created_at', '创建时间');
$form->display('updated_at', '修改时间');
});
}
WangEditor
编辑器