Quellcode durchsuchen

内容平台列表

duqinya vor 5 Jahren
Ursprung
Commit
19f01c49be

+ 35 - 0
app/Http/Controllers/V2/PlatformContentController.php

@@ -0,0 +1,35 @@
+<?php
+namespace App\Http\Controllers\V2;
+use App\Http\Controllers\BaseController;
+use App\Repositories\PlatformContentRepository;
+use App\Transformers\PlatformContentTransformer;
+use Illuminate\Http\Request;
+use League\Fractal\Resource\Collection;
+use League\Fractal\Manager;
+use League\Fractal\Pagination\IlluminatePaginatorAdapter;
+/**
+ * Created by PhpStorm.
+ * User: durong
+ * Date: 2019/6/17
+ * Time: 下午6:42
+ */
+
+class PlatformContentController extends BaseController
+{
+    public function __construct(PlatformContentRepository $platformContentRepository)
+    {
+        $this->platformContentRepository = $platformContentRepository;
+    }
+
+    //平台内容列表
+    public function index(Request $request)
+    {
+        $platformContent = $this->platformContentRepository->index($request->all());
+
+        $fractal = new Manager();
+        $resource = new Collection($platformContent , new PlatformContentTransformer());
+        $resource->setPaginator(new IlluminatePaginatorAdapter($platformContent));
+        $data = $fractal->createData($resource)->toArray();
+        return $this->jsonSuccess($data);
+    }
+}

+ 20 - 0
app/Models/PlatformContent.php

@@ -0,0 +1,20 @@
+<?php
+namespace App\Models;
+/**
+ * Created by PhpStorm.
+ * User: durong
+ * Date: 2019/6/17
+ * Time: 下午12:11
+ */
+
+class PlatformContent extends BaseModel
+{
+    protected  $table = 'platform_content';
+    /**
+     * 可被批量赋值的字段
+     * @var array
+     */
+    protected $fillable = ['title','content'];
+
+
+}

+ 29 - 0
app/Repositories/PlatformContentRepository.php

@@ -0,0 +1,29 @@
+<?php
+namespace App\Repositories;
+use App\Models\PlatformContent;
+use Symfony\Component\HttpKernel\Exception\HttpException;
+
+/**
+ * Created by PhpStorm.
+ * User: durong
+ * Date: 2019/6/17
+ * Time: 下午6:46
+ */
+
+class PlatformContentRepository
+{
+    public function __construct(PlatformContent $platformContent)
+    {
+        $this->platformContent = $platformContent;
+    }
+
+    public function index($request)
+    {
+        $perPage = isset($request['per_page']) ? $request['per_page'] : env('PER_PAGE');
+        $this->platformContent = $this->platformContent
+            ->orderBy('id', 'desc');
+
+        return $this->platformContent->paginate($perPage);
+    }
+
+}

+ 20 - 0
app/Transformers/PlatformContentTransformer.php

@@ -0,0 +1,20 @@
+<?php
+
+namespace App\Transformers;
+
+use App\Models\PlatformContent;
+use League\Fractal\TransformerAbstract;
+
+class PlatformContentTransformer extends TransformerAbstract
+{
+
+    public function transform(PlatformContent $platformContent)
+    {
+        return [
+            'id'  => $platformContent['id'],
+            'title'    => $platformContent['title'],
+            'content'    => $platformContent['content'],
+            'updated_at'    => date($platformContent['updated_at']),
+        ];
+    }
+}

+ 6 - 1
routes/api.php

@@ -53,9 +53,14 @@ $api->version('v1', [
     $api->group([
         'prefix' => 'v2'
     ], function ($api) {
-        $api->group(['middleware' => 'jwt.chxq_auth'], function ($api) {
+        $api->group(['middleware' => 'chxq_sign'], function ($api) {
             //根据多个ID获取banner
             $api->get('/bannerSet/lists', 'BannerController@lists');
+            //平台内容列表
+            $api->get('/platformContent/lists', 'PlatformContentController@index');
+            //星球新闻列表
+            $api->get('/starNews/lists', 'StarNewsController@index');
         });
+
     });
 });