Files
mtdb_movie/common/Channels/ChannelContentOrderController.php
maher 703f50a09d
Some checks failed
Build / run (push) Has been cancelled
first commit
2025-10-29 11:42:25 +01:00

37 lines
964 B
PHP
Executable File

<?php
namespace Common\Channels;
use App\Models\Channel;
use Common\Core\BaseController;
use Illuminate\Support\Facades\DB;
class ChannelContentOrderController extends BaseController
{
public function changeOrder(int $channelId)
{
$channel = Channel::findOrFail($channelId);
$this->authorize('update', $channel);
$data = request()->validate([
'ids' => 'array|min:1',
'ids.*' => 'int',
'modelType' => 'required|string',
]);
$queryPart = '';
foreach ($data['ids'] as $order => $id) {
$queryPart .= " when channelable_id=$id then $order";
}
DB::table('channelables')
->where('channel_id', $channel->id)
->whereIn('channelable_id', $data['ids'])
->where('channelable_type', $data['modelType'])
->update(['order' => DB::raw("(case $queryPart end)")]);
return $this->success();
}
}