You've already forked lubo_comment_query
添加建设内容
This commit is contained in:
35
app/Http/Controllers/ProgramConstructController.php
Normal file
35
app/Http/Controllers/ProgramConstructController.php
Normal file
@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Programs;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Routing\Controller as BaseController;
|
||||
|
||||
class ProgramConstructController extends BaseController
|
||||
{
|
||||
public function construct(Request $request) {
|
||||
$keyword = $request->get("keyword", "");
|
||||
$programs = Programs::query()->with(["appends", "video_pivots.video"])->where("status", "=", 0)->limit(15)->orderByDesc("created_at")->get();
|
||||
return view("program.construct.index", [
|
||||
"keyword" => $keyword,
|
||||
"programs"=>$programs,
|
||||
]);
|
||||
}
|
||||
|
||||
public function edit(Request $request, Programs $program) {
|
||||
return view("program.construct.create", [
|
||||
"program"=>$program
|
||||
]);
|
||||
}
|
||||
|
||||
public function submit(Request $request, Programs $program) {
|
||||
$updatePayload = $request->only(["name", "difficulty", "desc"]);
|
||||
$program->status = $request->post("status", 0);
|
||||
$program->created_at = $request->post("created_at");
|
||||
$program->update($updatePayload);
|
||||
return view("program.construct.create", [
|
||||
"program"=>$program
|
||||
]);
|
||||
}
|
||||
}
|
@ -10,8 +10,8 @@ class ProgramQueryController extends BaseController
|
||||
{
|
||||
public function index(Request $request) {
|
||||
$keyword = $request->get("keyword", "");
|
||||
$programs = Programs::query()->with(["appends", "video_pivots.video"])->limit(15)->orderByDesc("created_at")->get();
|
||||
return view("program", [
|
||||
$programs = Programs::query()->with(["appends", "video_pivots.video"])->where("status", "=", 1)->limit(15)->orderByDesc("created_at")->get();
|
||||
return view("program.index", [
|
||||
"keyword" => $keyword,
|
||||
"programs"=>$programs,
|
||||
]);
|
||||
|
45
app/Http/Controllers/ProgramVideoConstructController.php
Normal file
45
app/Http/Controllers/ProgramVideoConstructController.php
Normal file
@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Programs;
|
||||
use App\Models\ProgramVideos;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Routing\Controller as BaseController;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
class ProgramVideoConstructController extends BaseController
|
||||
{
|
||||
public function index(Request $request, Programs $program) {
|
||||
return view("program.construct.video.index", [
|
||||
"program" => $program,
|
||||
"videos" => $program->video_pivots,
|
||||
]);
|
||||
}
|
||||
|
||||
public function edit(Request $request, ProgramVideos $program_video) {
|
||||
return view("program.construct.video.create", [
|
||||
"program_video" => $program_video
|
||||
]);
|
||||
}
|
||||
|
||||
public function submit(Request $request, ProgramVideos $program_video) {
|
||||
$updatePayload = $request->only(["start_part", "start_time", "stop_part", "stop_time"]);
|
||||
if ($request->hasFile("start_image")) {
|
||||
$file = $request->file("start_image");
|
||||
$path = $file->store("lubo_file");
|
||||
$full_path = Storage::url($path);
|
||||
$program_video->start_image = str_replace("jerryyan.top", "jerryyan.net", $full_path);
|
||||
}
|
||||
if ($request->hasFile("stop_image")) {
|
||||
$file = $request->file("stop_image");
|
||||
$path = $file->store("lubo_file");
|
||||
$full_path = Storage::url($path);
|
||||
$program_video->stop_image = str_replace("jerryyan.top", "jerryyan.net", $full_path);
|
||||
}
|
||||
$program_video->update($updatePayload);
|
||||
return view("program.construct.video.create", [
|
||||
"program_video" => $program_video
|
||||
]);
|
||||
}
|
||||
}
|
@ -8,6 +8,8 @@ use Illuminate\Support\Carbon;
|
||||
|
||||
class ProgramVideos extends Model
|
||||
{
|
||||
protected $fillable = ["start_part", "start_time", "stop_part", "stop_time"];
|
||||
protected $dateFormat = 'U';
|
||||
public function program(): \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Programs::class, "program_id", "id");
|
||||
@ -21,7 +23,20 @@ class ProgramVideos extends Model
|
||||
public function startSec(): Attribute
|
||||
{
|
||||
return Attribute::get(function ($_, $attributes) {
|
||||
if (!$attributes['start_time']) {
|
||||
return "";
|
||||
}
|
||||
return Carbon::createFromFormat("H:i:s", $attributes['start_time'])->secondsSinceMidnight();
|
||||
});
|
||||
}
|
||||
|
||||
public function stopSec(): Attribute
|
||||
{
|
||||
return Attribute::get(function ($_, $attributes) {
|
||||
if (!$attributes['stop_time']) {
|
||||
return "";
|
||||
}
|
||||
return Carbon::createFromFormat("H:i:s", $attributes['stop_time'])->secondsSinceMidnight();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -6,6 +6,8 @@ use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Programs extends Model
|
||||
{
|
||||
protected $fillable = ["name", "difficulty", "desc"];
|
||||
protected $dateFormat = 'U';
|
||||
public function appends(): \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
{
|
||||
return $this->hasMany(ProgramAppends::class, "program_id", "id")->orderByDesc("is_original");
|
||||
|
Reference in New Issue
Block a user