Deploy Ladill Queue / deploy (push) Successful in 56s
Phases 1–6: tickets, counters, displays, appointments, workflows, rules, analytics, reports, feedback, admin, device API, and Gitea deploy workflow for queue.ladill.com. Co-authored-by: Cursor <cursoragent@cursor.com>
56 lines
1.8 KiB
PHP
56 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Api;
|
|
|
|
use App\Http\Controllers\Api\Concerns\ScopesApiToAccount;
|
|
use App\Http\Controllers\Controller;
|
|
use App\Models\Branch;
|
|
use App\Services\Qms\AuditLogger;
|
|
use App\Services\Qms\PlanService;
|
|
use Illuminate\Http\JsonResponse;
|
|
use Illuminate\Http\Request;
|
|
|
|
class BranchController extends Controller
|
|
{
|
|
use ScopesApiToAccount;
|
|
|
|
public function index(Request $request): JsonResponse
|
|
{
|
|
$this->authorizeAbility($request, 'admin.branches.view');
|
|
$branches = Branch::owned($this->ownerRef($request))
|
|
->where('organization_id', $this->organization($request)->id)
|
|
->orderBy('name')
|
|
->get();
|
|
|
|
return response()->json(['data' => $branches]);
|
|
}
|
|
|
|
public function store(Request $request): JsonResponse
|
|
{
|
|
$this->authorizeAbility($request, 'admin.branches.manage');
|
|
$organization = $this->organization($request);
|
|
$owner = $this->ownerRef($request);
|
|
|
|
$currentCount = Branch::owned($owner)->where('organization_id', $organization->id)->count();
|
|
abort_unless(app(PlanService::class)->canAddBranch($organization, $currentCount), 422, 'Branch limit reached for current plan.');
|
|
|
|
$validated = $request->validate([
|
|
'name' => ['required', 'string', 'max:255'],
|
|
'code' => ['nullable', 'string', 'max:50'],
|
|
'address' => ['nullable', 'string', 'max:500'],
|
|
'phone' => ['nullable', 'string', 'max:50'],
|
|
]);
|
|
|
|
$branch = Branch::create([
|
|
'owner_ref' => $owner,
|
|
'organization_id' => $organization->id,
|
|
...$validated,
|
|
'is_active' => true,
|
|
]);
|
|
|
|
AuditLogger::record($owner, 'branch.created', $organization->id, $owner, Branch::class, $branch->id);
|
|
|
|
return response()->json(['data' => $branch], 201);
|
|
}
|
|
}
|