first commit
This commit is contained in:
61
app/Http/Controllers/SubunitController.php
Normal file
61
app/Http/Controllers/SubunitController.php
Normal file
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
namespace App\Http\Controllers;
|
||||
use App\Models\Subunit;
|
||||
use App\Models\Unit;
|
||||
use Illuminate\Http\Request;
|
||||
use Inertia\Inertia;
|
||||
|
||||
class SubunitController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
$subunits = Subunit::with('unit.building')->latest()->paginate(15);
|
||||
return Inertia::render('Subunits/Index', ['subunits' => $subunits]);
|
||||
}
|
||||
|
||||
public function create()
|
||||
{
|
||||
$units = Unit::with('building')->get();
|
||||
return Inertia::render('Subunits/Create', ['units' => $units]);
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
$validated = $request->validate([
|
||||
'unit_id' => 'required|exists:units,id',
|
||||
'subunit_no' => 'required|string',
|
||||
'subunit_type' => 'required|string',
|
||||
'area_sqft' => 'nullable|integer',
|
||||
'status' => 'required|string',
|
||||
]);
|
||||
|
||||
Subunit::create($validated);
|
||||
return redirect()->route('subunits.index');
|
||||
}
|
||||
|
||||
public function edit(Subunit $subunit)
|
||||
{
|
||||
$units = Unit::with('building')->get();
|
||||
return Inertia::render('Subunits/Edit', ['subunit' => $subunit, 'units' => $units]);
|
||||
}
|
||||
|
||||
public function update(Request $request, Subunit $subunit)
|
||||
{
|
||||
$validated = $request->validate([
|
||||
'unit_id' => 'required|exists:units,id',
|
||||
'subunit_no' => 'required|string',
|
||||
'subunit_type' => 'required|string',
|
||||
'area_sqft' => 'nullable|integer',
|
||||
'status' => 'required|string',
|
||||
]);
|
||||
|
||||
$subunit->update($validated);
|
||||
return redirect()->route('subunits.index');
|
||||
}
|
||||
|
||||
public function destroy(Subunit $subunit)
|
||||
{
|
||||
$subunit->delete();
|
||||
return redirect()->route('subunits.index');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user