From f47b0bbd1475886e3ed36fa13a5361571c76d2e7 Mon Sep 17 00:00:00 2001 From: Jerry Yan <792602257@qq.com> Date: Tue, 1 Nov 2022 17:55:12 +0800 Subject: [PATCH] =?UTF-8?q?=E8=8A=82=E7=9B=AE=E5=BB=BA=E8=AE=BE=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E6=90=9C=E7=B4=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ProgramConstructController.php | 19 +++++++++++++++++-- .../views/program/construct/index.blade.php | 5 +++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/ProgramConstructController.php b/app/Http/Controllers/ProgramConstructController.php index 7f0c177..d191b62 100644 --- a/app/Http/Controllers/ProgramConstructController.php +++ b/app/Http/Controllers/ProgramConstructController.php @@ -7,8 +7,7 @@ use App\Models\ProgramVideos; use App\Models\VideoComments; use App\Models\VideoParts; use App\Util\ProgramVideoUtil; -use App\Util\TimeUtil; -use Carbon\Carbon; +use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\QueryException; use Illuminate\Http\Request; use Illuminate\Routing\Controller as BaseController; @@ -18,10 +17,26 @@ class ProgramConstructController extends BaseController { // region Views public function index(Request $request) { + $keyword = $request->get("keyword", ""); $status = $request->get("status", "0"); $query = Programs::query()->with(["appends", "video_pivots.video"])->where("status", $status, 0)->orderByDesc("created_at"); + if ($keyword) { + $keyword_split = explode(" ", $keyword); + foreach ($keyword_split as $_keyword) { + $_keyword = trim($_keyword); + if (mb_strlen($_keyword) > 0) { + $query->where(function (Builder $_query) use ($_keyword) { + $_query + ->where("name", "like", "%{$_keyword}%") + ->orWhere("difficulty", "like", "%{$_keyword}%") + ->orWhere("desc", "like", "%{$_keyword}%"); + }); + } + } + } $programs = $query->paginate(10)->withQueryString();; return view("program.construct.index", [ + "keyword" => $keyword, "programs"=>$programs, ]); } diff --git a/resources/views/program/construct/index.blade.php b/resources/views/program/construct/index.blade.php index 8d5c0f4..94a49b1 100644 --- a/resources/views/program/construct/index.blade.php +++ b/resources/views/program/construct/index.blade.php @@ -7,6 +7,11 @@
@include("common.header") +