<?php
namespace App\Admin\Controllers;
use App\File;
use App\Http\Controllers\Controller;
use Encore\Admin\Controllers\HasResourceActions;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Layout\Content;
use Encore\Admin\Show;
class ManageFileController extends Controller
{
use HasResourceActions;
public function index(Content $content)
{
return $content
->header('文件')
->description('列表')
->body($this->grid());
}
public function show($id, Content $content)
{
return $content
->header('文件')
->description('详情')
->body($this->detail($id));
}
public function edit($id, Content $content)
{
return $content
->header('编辑')
->description('文件')
->body($this->form()->edit($id));
}
public function create(Content $content)
{
return $content
->header('创建')
->description('文件')
->body($this->form());
}
protected function grid()
{
$grid = new Grid(new File);
$grid->status('状态')->switch();
$grid->name('文件名'); $grid->url('下载地址')->display(function ($url){
return "<a href='$url' target='_blank' download='$this->name'>下载</a>";
});
$grid->created_at('创建时间');
$grid->updated_at('更新时间');
return $grid;
}
protected function detail($id)
{
$show = new Show(File::findOrFail($id));
$show->id('Id');
$show->status('状态');
$show->name('文件名');
$show->url('文件');
return $show;
}
protected function form()
{
$form = new Form(new File);
$form->switch('status', '状态');
$form->text('name', '文件名');
$form->file('url', '文件');
return $form;
}
}