39 lines
1.1 KiB
PHP
39 lines
1.1 KiB
PHP
<?php
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Articles;
|
|
use Illuminate\Http\Request;
|
|
|
|
class ArticleController extends Controller {
|
|
|
|
|
|
public function article(Request $request){
|
|
$typestr = $request->get('type');
|
|
$lang = $request->get('lang', 'en');
|
|
$typepArr = [
|
|
'ann' => 1,
|
|
'faq' => 2,
|
|
'tut' => 3,
|
|
];
|
|
$type = $typepArr[$typestr] ?? 1;
|
|
$article = Articles::where(['type' => $type])->where(['lang' => $lang])->orderBy('id', 'desc')->first();
|
|
if (is_null($article)) {
|
|
header('Content-type: application/json');
|
|
$data = [
|
|
'title' => "暂无内容",
|
|
'content' => "暂无内容",
|
|
];
|
|
echo json_encode(['code' => 0, 'msg' => '','data'=>$data], 256);
|
|
exit;
|
|
} else {
|
|
header('Content-type: application/json');
|
|
$data = [
|
|
'title' => $article->title,
|
|
'content' => $article->content,
|
|
];
|
|
echo json_encode(['code' => 0, 'msg' => '', 'data' => $data], 256);
|
|
exit;
|
|
}
|
|
}
|
|
}
|