Pārlūkot izejas kodu

后台 小程序管理 轮播图

jingyuzhi 4 gadi atpakaļ
vecāks
revīzija
46a965e166

+ 95 - 0
app/Admin/Controllers/BannerController.php

xqd
@@ -0,0 +1,95 @@
+<?php
+
+namespace App\Admin\Controllers;
+
+use App\Models\Banner;
+use Encore\Admin\Controllers\AdminController;
+use Encore\Admin\Form;
+use Encore\Admin\Grid;
+use Encore\Admin\Show;
+
+class BannerController extends AdminController
+{
+    /**
+     * Title for current resource.
+     *
+     * @var string
+     */
+    protected $title = 'Banner';
+
+    /**
+     * Make a grid builder.
+     *
+     * @return Grid
+     */
+    protected function grid()
+    {
+        $grid = new Grid(new Banner());
+
+        $grid->column('id', __('Id'));
+        $grid->column('image', __('图片'))->image('',100,100);
+        $grid->column('type','类型')->using([1=>'用户端',2=>'医生端']);
+        $grid->column('url', __('链接'));
+        $states = [
+            'on'  => ['value' => 1, 'text' => '启用', 'color' => 'success'],
+            'off' => ['value' => 0, 'text' => '禁用', 'color' => 'danger'],
+        ];
+        $grid->column('status','状态')->switch($states);
+        $grid->column('created_at', __('创建时间'));
+        $grid->column('updated_at', __('更新时间'));
+        $grid->filter(function($filter){
+
+            // Remove the default id filter
+            $filter->disableIdFilter();
+
+            // Add a column filter
+            $type = [''=>'全部'];
+            $type = array_merge($type,Banner::$_post_type);
+            $filter->equal('type', '类别')->select(Banner::$_post_type);
+
+        });
+
+        return $grid;
+    }
+
+    /**
+     * Make a show builder.
+     *
+     * @param mixed $id
+     * @return Show
+     */
+    protected function detail($id)
+    {
+        $show = new Show(Banner::findOrFail($id));
+
+        $show->field('id', __('Id'));
+        $show->field('image', __('Image'))->image('',100,100);
+        $show->field('url', __('Url'));
+        $show->field('status', __('Status'));
+        $show->field('updated_at', __('Updated at'));
+        $show->field('created_at', __('Created at'));
+
+        return $show;
+    }
+
+    /**
+     * Make a form builder.
+     *
+     * @return Form
+     */
+    protected function form()
+    {
+        $form = new Form(new Banner());
+
+        $form->select('type' ,__('分类'))->options(Banner::$_post_type)->default('1');
+        $form->image('image', __('图片'))->rules('required' ,['required'=>'请选择图片!']);
+        $form->text('url', __('链接'));
+        $states = [
+            'off' => ['value' => 0, 'text' => '禁用', 'color' => 'danger'],
+            'on'  => ['value' => 1, 'text' => '启用', 'color' => 'success'],
+        ];
+        $form->switch('status','状态')->states($states);
+
+        return $form;
+    }
+}

+ 2 - 0
app/Admin/routes.php

xqd
@@ -17,5 +17,7 @@ Route::group([
     $router->resource('/organizations', OrganizationController::class);
     $router->resource('/docters', DocterController::class);
     $router->resource('/qualifications', QualificationController::class);
+    $router->resource('banners', BannerController::class);
+
 });
 

+ 15 - 0
app/Models/Banner.php

xqd
@@ -0,0 +1,15 @@
+<?php
+
+namespace App\Models;
+
+use Illuminate\Database\Eloquent\Model;
+
+class Banner extends Model
+{
+    //
+    protected $table = 'banner';
+    public static $_post_type = [
+        1=>'用户端',
+        2=>'医生端'
+    ];
+}

+ 37 - 0
database/migrations/2020_11_19_064648_bm_banner.php

xqd
@@ -0,0 +1,37 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+class BmBanner extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        //
+        Schema::create('banner', function (Blueprint $table) {
+            $table->increments('id');
+            $table->integer('type')->comment('分类 1.用户 2.医生');
+            $table->string('image')->comment('图片地址');
+            $table->string('url')->comment('链接')->nullable();
+            $table->integer('status')->comment('状态');
+            $table->dateTime('created_at')->comment('创建时间');
+            $table->dateTime('updated_at')->comment('更新时间');
+        });
+    }
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        //
+        Schema::drop('banner');
+    }
+}