generated from panliang/owl-admin-starter
45 lines
1.3 KiB
PHP
45 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Api;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use Illuminate\Http\Request;
|
|
use App\Models\{Article, Keyword};
|
|
use App\Http\Resources\ArticleResource;
|
|
|
|
class ArticleController extends Controller
|
|
{
|
|
// 共性指标
|
|
public function common()
|
|
{
|
|
$category = Keyword::where('key', 'category_1')->first();
|
|
if (!$category) {
|
|
return $this->response()->fail('文章不存在');
|
|
}
|
|
|
|
$article = Article::where('category_id', $category->id)->publish()->sort()->first();
|
|
if (!$article) {
|
|
return $this->response()->success('');
|
|
}
|
|
|
|
return $this->response()->success(ArticleResource::make($article));
|
|
}
|
|
|
|
// 进阶指标
|
|
public function cate()
|
|
{
|
|
$user = auth('api')->user();
|
|
$category = Keyword::where('key', 'category_2')->first();
|
|
if (!$category) {
|
|
return $this->response()->fail('文章不存在');
|
|
}
|
|
|
|
$article = Article::with(['partyCate'])->where('category_id', $category->id)->where('party_cate_id', $user->cate_id)->publish()->sort()->first();
|
|
if (!$article) {
|
|
return $this->response()->success('');
|
|
}
|
|
|
|
return $this->response()->success(ArticleResource::make($article));
|
|
}
|
|
}
|