feat: infrastructure assets management with warranty tracking and EAN lookup integration
This commit is contained in:
54
app/Http/Controllers/CommuneController.php
Normal file
54
app/Http/Controllers/CommuneController.php
Normal file
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Commune;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Inertia\Inertia;
|
||||
use Inertia\Response;
|
||||
|
||||
class CommuneController extends Controller
|
||||
{
|
||||
public function index(): Response
|
||||
{
|
||||
return Inertia::render('Communes/Index', [
|
||||
'communes' => Commune::withCount('commandes', 'contrats')->get(),
|
||||
]);
|
||||
}
|
||||
|
||||
public function store(Request $request): RedirectResponse
|
||||
{
|
||||
$validated = $request->validate([
|
||||
'nom' => 'required|string|max:100|unique:communes,nom',
|
||||
'code_postal' => 'nullable|string|max:10',
|
||||
]);
|
||||
|
||||
Commune::create($validated);
|
||||
|
||||
return back()->with('success', 'Commune créée.');
|
||||
}
|
||||
|
||||
public function update(Request $request, Commune $commune): RedirectResponse
|
||||
{
|
||||
$validated = $request->validate([
|
||||
'nom' => 'required|string|max:100|unique:communes,nom,' . $commune->id,
|
||||
'code_postal' => 'nullable|string|max:10',
|
||||
]);
|
||||
|
||||
$commune->update($validated);
|
||||
|
||||
return back()->with('success', 'Commune mise à jour.');
|
||||
}
|
||||
|
||||
public function destroy(Commune $commune): RedirectResponse
|
||||
{
|
||||
if ($commune->commandes()->exists() || $commune->contrats()->exists()) {
|
||||
return back()->with('error', 'Impossible de supprimer une commune liée à des commandes ou des contrats.');
|
||||
}
|
||||
|
||||
$commune->delete();
|
||||
|
||||
return back()->with('success', 'Commune supprimée.');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user