You've already forked lubo_comment_query
app
Console
Exceptions
Http
Controllers
CommentQueryController.php
DanmakuQueryController.php
FileController.php
ProgramAppendConstructController.php
ProgramConstructController.php
ProgramQueryController.php
ProgramVideoConstructController.php
Middleware
Kernel.php
Models
Providers
bootstrap
config
database
public
resources
routes
storage
tests
.editorconfig
.env.example
.gitattributes
.gitignore
.styleci.yml
README.md
artisan
composer.json
composer.lock
package.json
phpunit.xml
server.php
tailwind.config.js
webpack.mix.js
yarn.lock
46 lines
1.5 KiB
PHP
46 lines
1.5 KiB
PHP
<?php
|
|
|
|
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
|
|
{
|
|
public function index()
|
|
{
|
|
$video_list = Videos::query()
|
|
->withCount("danmakus", "bilibili_danmakus", "ixigua_danmakus", "douyin_danmakus")
|
|
->orderByDesc("created_at")
|
|
->paginate(10);
|
|
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", "");
|
|
$query = VideoDanmakus::query()->where("video_bvid", "=", $bvid);
|
|
if ($keyword) {
|
|
$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")->paginate(20);
|
|
return view("danmaku.search_index", [
|
|
"keyword" => $keyword,
|
|
"video" => $video,
|
|
"danmakus" => $danmakus,
|
|
]);
|
|
}
|
|
}
|