Files
ladill-frontdesk/app/Http/Controllers/Frontdesk/BuildingController.php
T
isaacclad 5526a10342
Deploy Ladill Frontdesk / deploy (push) Successful in 48s
Move Branches and Team into Settings as Pro features.
Gate multi-branch and team management behind paid plans, nest their
routes under Settings, and remove them from the sidebar Administration
section.
2026-07-16 08:13:42 +00:00

80 lines
2.4 KiB
PHP

<?php
namespace App\Http\Controllers\Frontdesk;
use App\Http\Controllers\Controller;
use App\Http\Controllers\Frontdesk\Concerns\RequiresPlanFeature;
use App\Http\Controllers\Frontdesk\Concerns\ScopesToAccount;
use App\Models\Branch;
use App\Models\Building;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\View\View;
class BuildingController extends Controller
{
use RequiresPlanFeature;
use ScopesToAccount;
private const FEATURE = 'branches';
private const UPGRADE_MESSAGE = 'Multi-branch management requires Frontdesk Pro.';
public function index(Request $request, Branch $branch): View
{
$this->authorizeAbility($request, 'admin.branches.view');
$this->authorizeOwner($request, $branch);
if ($upgrade = $this->proFeatureUpgradeView(
$request,
self::FEATURE,
'Branches',
'Manage buildings and reception desks with Frontdesk Pro.',
)) {
return $upgrade;
}
$buildings = $branch->buildings()->withCount('receptionDesks')->orderBy('name')->get();
return view('frontdesk.admin.buildings.index', compact('branch', 'buildings'));
}
public function store(Request $request, Branch $branch): RedirectResponse
{
$this->authorizeAbility($request, 'admin.branches.manage');
$this->authorizeOwner($request, $branch);
if ($deny = $this->denyWithoutFeature($request, self::FEATURE, self::UPGRADE_MESSAGE)) {
return $deny;
}
$validated = $request->validate([
'name' => ['required', 'string', 'max:255'],
'floor_count' => ['nullable', 'string', 'max:20'],
]);
Building::create([
'owner_ref' => $this->ownerRef($request),
'branch_id' => $branch->id,
...$validated,
]);
return back()->with('success', 'Building added.');
}
public function destroy(Request $request, Branch $branch, Building $building): RedirectResponse
{
$this->authorizeAbility($request, 'admin.branches.manage');
$this->authorizeOwner($request, $building);
abort_unless($building->branch_id === $branch->id, 404);
if ($deny = $this->denyWithoutFeature($request, self::FEATURE, self::UPGRADE_MESSAGE)) {
return $deny;
}
$building->delete();
return back()->with('success', 'Building removed.');
}
}