65 lines
1.5 KiB
PHP
65 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Models\Tenant;
|
|
use Illuminate\Http\Request;
|
|
use Inertia\Inertia;
|
|
|
|
class TenantController extends Controller
|
|
{
|
|
public function index()
|
|
{
|
|
if (!auth()->user()->isSuperAdmin()) {
|
|
abort(403, 'Unauthorized action.');
|
|
}
|
|
|
|
$tenants = Tenant::orderBy('name')->get();
|
|
|
|
return Inertia::render('Admin/Tenants/Index', [
|
|
'tenants' => $tenants
|
|
]);
|
|
}
|
|
|
|
public function store(Request $request)
|
|
{
|
|
if (!auth()->user()->isSuperAdmin()) {
|
|
abort(403, 'Unauthorized action.');
|
|
}
|
|
|
|
$request->validate([
|
|
'name' => 'required|string|max:255|unique:tenants,name',
|
|
]);
|
|
|
|
Tenant::create($request->only('name'));
|
|
|
|
return back()->with('success', 'Structure créée avec succès.');
|
|
}
|
|
|
|
public function update(Request $request, Tenant $tenant)
|
|
{
|
|
if (!auth()->user()->isSuperAdmin()) {
|
|
abort(403, 'Unauthorized action.');
|
|
}
|
|
|
|
$request->validate([
|
|
'name' => 'required|string|max:255|unique:tenants,name,' . $tenant->id,
|
|
]);
|
|
|
|
$tenant->update($request->only('name'));
|
|
|
|
return back()->with('success', 'Structure mise à jour.');
|
|
}
|
|
|
|
public function destroy(Tenant $tenant)
|
|
{
|
|
if (!auth()->user()->isSuperAdmin()) {
|
|
abort(403, 'Unauthorized action.');
|
|
}
|
|
|
|
$tenant->delete();
|
|
|
|
return back()->with('success', 'Structure supprimée.');
|
|
}
|
|
}
|