xiaogang hace 4 años
padre
commit
f92cabc388

+ 4 - 4
app/Admin/Controllers/BannerController.php

xqd xqd
@@ -25,10 +25,10 @@ class BannerController extends AdminController
             $grid->column('status');
             $grid->column('created_at');
             $grid->column('updated_at')->sortable();
-        
+
             $grid->filter(function (Grid\Filter $filter) {
                 $filter->equal('id');
-        
+
             });
         });
     }
@@ -63,10 +63,10 @@ class BannerController extends AdminController
         return Form::make(new Banner(), function (Form $form) {
             $form->display('id');
             $form->text('title');
-            $form->text('img_url');
+            $form->image('img_url')->uniqueName()->removable(false);
             $form->text('site');
             $form->text('status');
-        
+
             $form->display('created_at');
             $form->display('updated_at');
         });

+ 1 - 0
app/Admin/routes.php

xqd
@@ -13,5 +13,6 @@ Route::group([
 ], function (Router $router) {
 
     $router->get('/', 'HomeController@index');
+    $router->resource('/banner', 'BannerController');
 
 });

+ 2 - 0
app/Http/Controllers/Api/UploadController.php

xqd
@@ -14,12 +14,14 @@ class UploadController extends Controller
         try {
             //获取上传的文件
             $file = $request->file('file');
+
             //获取上传图片的临时地址
             $tmppath = $file->getRealPath();
             //生成文件名
             $fileName = rand(1000,9999). time() .date('ymd') . '.' . $file->getClientOriginalExtension();
             //拼接上传的文件夹路径(按照日期格式1810/17/xxxx.jpg)
             $pathName = 'chengluApp/'.date('Y-m/d').'/'.$fileName;
+
             //上传图片到阿里云OSS
             OSS::publicUpload(env('ALI_OSS_BUCKET'), $pathName, $tmppath, ['ContentType' => $file->getClientMimeType()]);
             //获取上传图片的Url链接

+ 0 - 2
app/Services/OSS.php

xqd
@@ -43,9 +43,7 @@ class OSS {
      */
     public static function publicUpload($bucketName, $ossKey, $filePath, $options = [])
     {
-
         $oss = new OSS();
-
         $oss->ossClient->setBucket($bucketName);
         return $oss->ossClient->uploadFile($ossKey, $filePath, $options);
     }

+ 1 - 0
composer.json

xqd
@@ -13,6 +13,7 @@
         "fruitcake/laravel-cors": "^2.0",
         "guzzlehttp/guzzle": "^7.0.1",
         "johnlui/aliyun-oss": "~2.0",
+        "juhedata/aliyun-oss": "^2.2",
         "laravel/framework": "^8.40",
         "laravel/tinker": "^2.5",
         "liyu/dingo-serializer-switch": "^0.3.2",

+ 46 - 1
composer.lock

xqd xqd
@@ -4,7 +4,7 @@
         "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
         "This file is @generated automatically"
     ],
-    "content-hash": "60023a0be7324c8630c5fe31b8ab6111",
+    "content-hash": "394593e271884669d966e2b5bd8be40e",
     "packages": [
         {
             "name": "asm89/stack-cors",
@@ -1372,6 +1372,51 @@
             },
             "time": "2017-04-06T06:48:21+00:00"
         },
+        {
+            "name": "juhedata/aliyun-oss",
+            "version": "v2.2.4",
+            "source": {
+                "type": "git",
+                "url": "https://github.com/juhedata/aliyun-oss.git",
+                "reference": "27da2bf8ad16bc1a6cc6dc2ad4e6ca24594cb81f"
+            },
+            "dist": {
+                "type": "zip",
+                "url": "https://api.github.com/repos/juhedata/aliyun-oss/zipball/27da2bf8ad16bc1a6cc6dc2ad4e6ca24594cb81f",
+                "reference": "27da2bf8ad16bc1a6cc6dc2ad4e6ca24594cb81f",
+                "shasum": "",
+                "mirrors": [
+                    {
+                        "url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%",
+                        "preferred": true
+                    }
+                ]
+            },
+            "require": {
+                "php": ">=7.2.0",
+                "symfony/event-dispatcher": "^5.0"
+            },
+            "type": "library",
+            "autoload": {
+                "files": [
+                    "src/AliYunOSS.php"
+                ]
+            },
+            "notification-url": "https://packagist.org/downloads/",
+            "license": [
+                "MIT"
+            ],
+            "description": "阿里云 OSS 官方 SDK 的 Composer 封装,支持 PHP7.2 项目,包括 Laravel、Symfony、TinyLara 等等。",
+            "keywords": [
+                "AliyunOSS",
+                "aliyun",
+                "oss"
+            ],
+            "support": {
+                "source": "https://github.com/juhedata/aliyun-oss/tree/v2.2.4"
+            },
+            "time": "2021-01-20T01:28:54+00:00"
+        },
         {
             "name": "laravel/framework",
             "version": "v8.47.0",