feat: multi-tenant SaaS implementation - admin interface, tenant isolation, and UI updates
This commit is contained in:
64
app/Http/Controllers/TenantController.php
Normal file
64
app/Http/Controllers/TenantController.php
Normal file
@@ -0,0 +1,64 @@
|
||||
<?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.');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user