You've already forked lubo_comment_query
复制常驻时,勾选批量复制
This commit is contained in:
@ -4,6 +4,7 @@ namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\ProgramAppends;
|
||||
use App\Models\Programs;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Routing\Controller as BaseController;
|
||||
|
||||
@ -36,8 +37,18 @@ class ProgramAppendConstructController extends BaseController
|
||||
}
|
||||
|
||||
public function copy_view(Request $request, Programs $program) {
|
||||
$programsId = Programs::query()->select("id")
|
||||
->where("created_at", "<", $program->created_at->addWeeks(2))
|
||||
->where("created_at", ">", $program->created_at->addWeeks(-2))
|
||||
->pluck("id");
|
||||
$broadcastList = ProgramAppends::query()->groupBy("name", "from")
|
||||
->whereIn("program_id", $programsId)
|
||||
->where("broadcast", "=", 1)
|
||||
->select("name", "from")->selectRaw("max(id) as id")
|
||||
->orderBy("id")->get();
|
||||
return view("program.construct.append.copy_broadcast", [
|
||||
"program" => $program,
|
||||
"broadcastList" => $broadcastList,
|
||||
]);
|
||||
}
|
||||
// endregion
|
||||
@ -61,13 +72,15 @@ class ProgramAppendConstructController extends BaseController
|
||||
|
||||
public function copy_append(Request $request, Programs $program) {
|
||||
$payload = $request->validate([
|
||||
"id" => ["required", "numeric", "exists:App\Models\ProgramAppends,id"]
|
||||
"ids" => ["required", "array", "exists:App\Models\ProgramAppends,id"]
|
||||
]);
|
||||
$original_append = ProgramAppends::query()->findOrFail($payload["id"]);
|
||||
$append = $original_append->replicate();
|
||||
$program->appends()->save($append);
|
||||
$original_appends = ProgramAppends::query()->findMany($payload["ids"]);
|
||||
$appends = $original_appends->map(function ($append) {
|
||||
return $append->replicate();
|
||||
});
|
||||
$program->appends()->saveMany($appends);
|
||||
return redirect(route("program.construct.append.list", [
|
||||
"program"=>$append->program->id,
|
||||
"program"=>$program->id,
|
||||
]));
|
||||
}
|
||||
// endregion
|
||||
|
Reference in New Issue
Block a user