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
|
||||
|
34
app/View/Components/Appends/AppendList.php
Normal file
34
app/View/Components/Appends/AppendList.php
Normal file
@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace App\View\Components\Appends;
|
||||
|
||||
use App\Models\ProgramAppends;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\View\Component;
|
||||
|
||||
class AppendList extends Component
|
||||
{
|
||||
/**
|
||||
* @var ProgramAppends[]|Collection
|
||||
*/
|
||||
public $appends;
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
public $enableEdit;
|
||||
|
||||
/**
|
||||
* @param $appends ProgramAppends|Collection
|
||||
* @param bool $enableEdit
|
||||
*/
|
||||
public function __construct($appends, bool $enableEdit=true)
|
||||
{
|
||||
$this->appends = $appends;
|
||||
$this->enableEdit = $enableEdit;
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
return view('components.appends.list');
|
||||
}
|
||||
}
|
32
app/View/Components/Appends/AppendListItem.php
Normal file
32
app/View/Components/Appends/AppendListItem.php
Normal file
@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace App\View\Components\Appends;
|
||||
|
||||
use App\Models\ProgramAppends;
|
||||
use Illuminate\View\Component;
|
||||
|
||||
class AppendListItem extends Component
|
||||
{
|
||||
/**
|
||||
* @var ProgramAppends
|
||||
*/
|
||||
public $append;
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
public $enableEdit;
|
||||
|
||||
/**
|
||||
* @param $append ProgramAppends
|
||||
*/
|
||||
public function __construct(ProgramAppends $append, bool $enableEdit=true)
|
||||
{
|
||||
$this->append = $append;
|
||||
$this->enableEdit = $enableEdit;
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
return view('components.appends.item');
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user