You've already forked lubo_comment_query
弹幕查询
This commit is contained in:
@ -2,7 +2,9 @@
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\VideoDanmakus;
|
||||
use App\Models\Videos;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Routing\Controller as BaseController;
|
||||
|
||||
class DanmakuQueryController extends BaseController
|
||||
@ -10,8 +12,33 @@ class DanmakuQueryController extends BaseController
|
||||
public function index()
|
||||
{
|
||||
$video_list = Videos::query()->withCount("danmakus")->orderByDesc("created_at")->limit(20)->get();
|
||||
return view("danmaku", [
|
||||
return view("danmaku.index", [
|
||||
"video_list" => $video_list,
|
||||
]);
|
||||
}
|
||||
|
||||
public function specific_search(Request $request, string $bvid)
|
||||
{
|
||||
$video = Videos::query()->withCount("danmakus")->where("bvid", "=", $bvid)->firstOrFail();
|
||||
$keyword = $request->get("keyword", "");
|
||||
if ($keyword) {
|
||||
$query = VideoDanmakus::query()->where("video_bvid", "=", $bvid);
|
||||
$keyword_split = explode(" ", $keyword);
|
||||
foreach ($keyword_split as $_keyword) {
|
||||
if (mb_strlen(trim($_keyword)) > 0) {
|
||||
$query->where(function ($_query) use ($_keyword) {
|
||||
$_query->where("content", "like", "%{$_keyword}%", "or")->where("from", "like", "%${_keyword}%", "or");
|
||||
});
|
||||
}
|
||||
}
|
||||
$danmakus = $query->orderBy("created_at", "asc")->get();
|
||||
} else {
|
||||
$danmakus = [];
|
||||
}
|
||||
return view("danmaku.search_index", [
|
||||
"keyword" => $keyword,
|
||||
"video" => $video,
|
||||
"danmakus" => $danmakus,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user