| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- <?php
- /**
- * Created by PhpStorm.
- * User: ring
- * Date: 2019/7/22
- * Time: 下午1:45
- */
- namespace App\Admin\Controllers;
- use App\Models\Gifts;
- use Encore\Admin\Controllers\AdminController;
- use Encore\Admin\Form;
- use Encore\Admin\Grid;
- use Illuminate\Support\Facades\Cache;
- class GiftController extends AdminController
- {
- protected $title = '礼物管理';
- protected function grid()
- {
- $grid = new Grid(new Gifts());
- $grid->id('ID')->sortable();
- $grid->column('name', '名称');
- $grid->column('file', '图片')->image(config('love.QINIU_MY_DOMAINS'),100,100);
- $grid->column('type', '类型')->display(function ($android) {
- return $android? 'VIP礼物' : '普通礼物';
- });
- $grid->column('svga', 'svga');
- $grid->column('size', '动画展示次数');
- $grid->column('rose', '玫瑰数');
- $grid->column('sort', '排序');
- $grid->updated_at('修改时间');
- $grid->created_at('创建时间');
- $grid->disableFilter();
- $grid->disableExport();
- $grid->disableRowSelector();
- $grid->disableColumnSelector();
- $grid->actions(function ($actions) {
- if( $actions->getKey()==1){
- $actions->disableDelete();
- $actions->disableEdit();
- }
- $actions->disableView();
- });
- return $grid;
- }
- protected function form()
- {
- $form = new Form(new Gifts);
- $form->text('name', '名称')->rules('required|min:1');
- $form->select('type', '类型')->options([0 => '普通礼物', 1 => 'VIP礼物',]);
- $form->image('file','图片')->uniqueName();
- $form->url('svga', 'svga素材')->help('到这里寻求帮助http://svga.io');
- $form->number('rose', '玫瑰数')->default(1);
- $form->number('size', '动画展示次数')->default(1);
- $form->number('sort', '排序')->default(1);
- $form->footer(function ($footer) {
- $footer->disableReset();
- $footer->disableViewCheck();
- $footer->disableEditingCheck();
- $footer->disableCreatingCheck();
- });
- $form->tools(function (Form\Tools $tools) {
- $tools->disableView();
- });
- return $form;
- }
- public function store()
- {
- Cache::forget('Gift');
- return $this->form()->store();
- }
- public function update($id)
- {
- Cache::forget('Gift');
- return $this->form()->update($id);
- }
- public function destroy($id)
- {
- Cache::forget('Gift');
- $student=Gifts::where('id',$id)->first();
- $student->delete();
- if($student->trashed()){
- $response = [
- 'status' => true,
- 'message' => trans('admin.delete_succeeded'),
- ];
- }else{
- $response = [
- 'status' => false,
- 'message' => '删除失败',
- ];
- }
- return response()->json($response);
- }
- }
|