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

51 lines
1.2 KiB
PHP
Executable File

<?php
namespace App\Http\Controllers;
use App\Models\Channel;
use Common\Core\BaseController;
use Illuminate\Support\Str;
class ChannelItemController extends BaseController
{
public function add(Channel $channel)
{
$this->authorize('update', $channel);
$data = $this->validate(request(), [
'itemId' => 'required|integer',
'itemType' => 'required|string',
]);
$relationName = Str::plural($data['itemType']);
$channel->$relationName()->sync(
[
$data['itemId'] => [
'order' => $channel->$relationName()->count() + 1,
],
],
false,
);
$channel->touch();
return $this->success(['channel' => $channel]);
}
public function remove(Channel $channel)
{
$this->authorize('update', $channel);
$data = $this->validate(request(), [
'itemId' => 'required|integer',
'itemType' => 'required|string',
]);
$relationName = Str::plural($data['itemType']);
$channel->$relationName()->detach($data['itemId']);
$channel->touch();
return $this->success(['channel' => $channel]);
}
}