82 lines
2.2 KiB
PHP
82 lines
2.2 KiB
PHP
<?php
|
||
|
||
namespace App\Admin\Controllers;
|
||
|
||
use App\Admin\Repositories\Article;
|
||
use Dcat\Admin\Form;
|
||
use Dcat\Admin\Grid;
|
||
use Dcat\Admin\Show;
|
||
use Dcat\Admin\Http\Controllers\AdminController;
|
||
use Carbon\Carbon;
|
||
|
||
class ArticleController extends AdminController
|
||
{
|
||
|
||
protected $title = '文章管理';
|
||
/**
|
||
* Make a grid builder.
|
||
*
|
||
* @return Grid
|
||
*/
|
||
protected function grid()
|
||
{
|
||
return Grid::make(new Article(), function (Grid $grid) {
|
||
$grid->column('id')->sortable();
|
||
$grid->column('title');
|
||
$grid->column('cover_res')->image(100, 100);
|
||
$grid->column('jump_link', '跳转链接');
|
||
// $grid->column('content');
|
||
$grid->column('created_at');
|
||
$grid->column('updated_at')->sortable();
|
||
|
||
$grid->filter(function (Grid\Filter $filter) {
|
||
// $filter->equal('id');
|
||
$filter->like('title');
|
||
});
|
||
});
|
||
}
|
||
|
||
/**
|
||
* Make a show builder.
|
||
*
|
||
* @param mixed $id
|
||
*
|
||
* @return Show
|
||
*/
|
||
protected function detail($id)
|
||
{
|
||
return Show::make($id, new Article(), function (Show $show) {
|
||
$show->field('id');
|
||
$show->field('title');
|
||
$show->field('cover_res')->image(100, 100);
|
||
$show->field('jump_link', '跳转链接');
|
||
$show->field('content')->unescape();
|
||
$show->field('created_at');
|
||
$show->field('updated_at');
|
||
});
|
||
}
|
||
|
||
/**
|
||
* Make a form builder.
|
||
*
|
||
* @return Form
|
||
*/
|
||
protected function form()
|
||
{
|
||
return Form::make(new Article(), function (Form $form) {
|
||
$form->display('id');
|
||
$form->text('title')->required();
|
||
$form->text('jump_link', '跳转链接');
|
||
$form->image('cover_res')
|
||
->accept('jpg,png,gif,jpeg', 'image/*')
|
||
->move('milk-tea/article/'.Carbon::now()->toDateString())
|
||
->saveFullUrl()->removable(false)
|
||
->required()->help('建议图片尺寸:686*388');
|
||
$form->editor('content');
|
||
|
||
$form->display('created_at');
|
||
$form->display('updated_at');
|
||
});
|
||
}
|
||
}
|