Some checks failed
Tests / PHP 8.1 (push) Has been cancelled
Tests / PHP 8.2 (push) Has been cancelled
Tests / PHP 8.3 (push) Has been cancelled
51 lines
1.3 KiB
PHP
51 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace Modules\EcommerceFinance\Http\Controllers\Api;
|
|
|
|
use App\Abstracts\Http\ApiController;
|
|
use Modules\EcommerceFinance\Http\Requests\Channel as Request;
|
|
use Modules\EcommerceFinance\Models\Channel;
|
|
|
|
class Channels extends ApiController
|
|
{
|
|
public function index()
|
|
{
|
|
return response()->json(Channel::query()->orderBy('name')->paginate($this->limit()));
|
|
}
|
|
|
|
public function show(Channel $channel)
|
|
{
|
|
return response()->json($channel);
|
|
}
|
|
|
|
public function store(Request $request)
|
|
{
|
|
$channel = Channel::create($this->attributes($request));
|
|
|
|
return response()
|
|
->json($channel, 201)
|
|
->header('Location', route('api.ecommerce-finance.channels.show', $channel));
|
|
}
|
|
|
|
public function update(Channel $channel, Request $request)
|
|
{
|
|
$channel->update($request->validated());
|
|
|
|
return response()->json($channel->fresh());
|
|
}
|
|
|
|
private function attributes(Request $request): array
|
|
{
|
|
return array_merge($request->validated(), [
|
|
'company_id' => company_id(),
|
|
'created_by' => user_id(),
|
|
'created_from' => 'ecommerce-finance',
|
|
]);
|
|
}
|
|
|
|
private function limit(): int
|
|
{
|
|
return min(max((int) request('limit', 25), 1), 100);
|
|
}
|
|
}
|