|
|
@ -0,0 +1,35 @@ |
|
|
|
|
|
<?php |
|
|
|
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\Api; |
|
|
|
|
|
|
|
|
|
|
|
use App\Http\Controllers\Controller; |
|
|
|
|
|
use App\Models\Article; |
|
|
|
|
|
use Illuminate\Http\Request; |
|
|
|
|
|
|
|
|
|
|
|
class ArticleController extends Controller |
|
|
|
|
|
{ |
|
|
|
|
|
//文章列表
|
|
|
|
|
|
public function index() |
|
|
|
|
|
{ |
|
|
|
|
|
$list = Article::where('agent_id', $this->agent_id) |
|
|
|
|
|
->select('id', 'image', 'title', 'updated_at') |
|
|
|
|
|
->orderBy('id', 'DESC') |
|
|
|
|
|
->simplePaginate(15); |
|
|
|
|
|
return $this->success($list); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//文章详情
|
|
|
|
|
|
public function show() |
|
|
|
|
|
{ |
|
|
|
|
|
$id = request()->input('id'); |
|
|
|
|
|
if (!$id || !ctype_digit($id)) { |
|
|
|
|
|
return $this->error('未指定文章ID'); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
$article = Article::where('agent_id', $this->agent_id)->find($id); |
|
|
|
|
|
if (!$article) { |
|
|
|
|
|
return $this->error('文章不存在或已被删除'); |
|
|
|
|
|
} |
|
|
|
|
|
return $this->success($article); |
|
|
|
|
|
} |
|
|
|
|
|
} |