diff --git a/app/Http/Controllers/DanmakuQueryController.php b/app/Http/Controllers/DanmakuQueryController.php index 2d6c043..2a9fe68 100644 --- a/app/Http/Controllers/DanmakuQueryController.php +++ b/app/Http/Controllers/DanmakuQueryController.php @@ -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, + ]); + } } diff --git a/resources/views/danmaku.blade.php b/resources/views/danmaku/index.blade.php similarity index 100% rename from resources/views/danmaku.blade.php rename to resources/views/danmaku/index.blade.php diff --git a/resources/views/danmaku/search_index.blade.php b/resources/views/danmaku/search_index.blade.php new file mode 100644 index 0000000..34ba8ab --- /dev/null +++ b/resources/views/danmaku/search_index.blade.php @@ -0,0 +1,53 @@ + +
+ +发送人 | +弹幕内容 | +发送时间 | +
+ @switch($danmaku->platform_id)
+ @case(1)
+ |
+ {{$danmaku->content}} | +{{$danmaku->created_at}} | +