You've already forked lubo_comment_query
支持复制常驻留言
This commit is contained in:
@ -9,6 +9,7 @@ use Illuminate\Routing\Controller as BaseController;
|
||||
|
||||
class ProgramAppendConstructController extends BaseController
|
||||
{
|
||||
// region Views
|
||||
public function index(Request $request, Programs $program) {
|
||||
return view("program.construct.append.index", [
|
||||
"program" => $program,
|
||||
@ -27,21 +28,6 @@ class ProgramAppendConstructController extends BaseController
|
||||
]);
|
||||
}
|
||||
|
||||
public function create(Request $request, Programs $program) {
|
||||
$request->validate([
|
||||
"name" => ["required_without:is_original"],
|
||||
"from" => ["required"],
|
||||
"price" => ["required", "numeric"],
|
||||
]);
|
||||
$createPayload = $request->only(["name", "from", "price", "append"]);
|
||||
$append = $program->appends()->create($createPayload);
|
||||
$append->is_original = $request->post("is_original", 0);
|
||||
$append->save();
|
||||
return redirect(route("program.construct.append.list", [
|
||||
"program"=>$program->id,
|
||||
]));
|
||||
}
|
||||
|
||||
public function edit(Request $request, ProgramAppends $append) {
|
||||
return view("program.construct.append.create", [
|
||||
"program" => $append->program,
|
||||
@ -49,16 +35,44 @@ class ProgramAppendConstructController extends BaseController
|
||||
]);
|
||||
}
|
||||
|
||||
public function copy_view(Request $request, Programs $program) {
|
||||
return view("program.construct.append.copy_broadcast", [
|
||||
"program" => $program,
|
||||
]);
|
||||
}
|
||||
// endregion
|
||||
|
||||
// region Form Submits
|
||||
public function create(Request $request, Programs $program) {
|
||||
$append = $this->fill_model($request);
|
||||
$program->appends()->save($append);
|
||||
return redirect(route("program.construct.append.list", [
|
||||
"program"=>$program->id,
|
||||
]));
|
||||
}
|
||||
|
||||
public function submit(Request $request, ProgramAppends $append) {
|
||||
$submitPayload = $request->only(["name", "from", "price", "append"]);
|
||||
$append->update($submitPayload);
|
||||
$append->is_original = $request->post("is_original", 0);
|
||||
$append = $this->fill_model($request, $append);
|
||||
$append->save();
|
||||
return redirect(route("program.construct.append.list", [
|
||||
"program"=>$append->program->id,
|
||||
]));
|
||||
}
|
||||
|
||||
public function copy_append(Request $request, Programs $program) {
|
||||
$payload = $request->validate([
|
||||
"id" => ["required", "numeric", "exists:App\Models\ProgramAppends,id"]
|
||||
]);
|
||||
$original_append = ProgramAppends::query()->findOrFail($payload["id"]);
|
||||
$append = $original_append->replicate();
|
||||
$program->appends()->save($append);
|
||||
return redirect(route("program.construct.append.list", [
|
||||
"program"=>$append->program->id,
|
||||
]));
|
||||
}
|
||||
// endregion
|
||||
|
||||
// region API
|
||||
public function from_list(Request $request) {
|
||||
$query = ProgramAppends::query()->groupBy("from")
|
||||
->select("from")
|
||||
@ -73,4 +87,35 @@ class ProgramAppendConstructController extends BaseController
|
||||
];
|
||||
})->toArray();
|
||||
}
|
||||
|
||||
public function broadcast_list(Request $request) {
|
||||
$query = ProgramAppends::query()->groupBy("name")
|
||||
->where("broadcast", "=", 1)
|
||||
->select("name")->selectRaw("max(id) as id");
|
||||
return $query->get()->map(function ($item) {
|
||||
return [
|
||||
"text" => $item["name"],
|
||||
"value" => $item["id"],
|
||||
"alias" => implode("", \pinyin($item["name"], PINYIN_NO_TONE|PINYIN_KEEP_ENGLISH)),
|
||||
"abbr" => \pinyin_abbr($item["name"]),
|
||||
];
|
||||
});
|
||||
}
|
||||
// endregion
|
||||
|
||||
private function fill_model(Request $request, ?ProgramAppends $append = null): ProgramAppends
|
||||
{
|
||||
if ($append === null) {
|
||||
$append = new ProgramAppends();
|
||||
}
|
||||
$payload = $request->validate([
|
||||
"name" => ["required_without:is_original"],
|
||||
"from" => ["required"],
|
||||
"price" => ["required", "numeric"],
|
||||
"post" => [],
|
||||
]);
|
||||
$append->fill($payload);
|
||||
$append->is_original = $request->post("is_original", 0);
|
||||
return $append;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user