Teren-app/app/Http/Controllers/ContractController.php
2025-11-06 21:54:07 +01:00

62 lines
1.7 KiB
PHP

<?php
namespace App\Http\Controllers;
use App\Models\Contract;
use Illuminate\Http\Request;
use Inertia\Inertia;
class ContractController extends Controller
{
public function index(Contract $contract)
{
return Inertia::render('Contract/Index', [
'contracts' => $contract::with(['type', 'debtor'])
->where('active', 1)
->orderByDesc('created_at')
->paginate(10),
'person_types' => \App\Models\Person\PersonType::all(['id', 'name', 'description'])
->where('deleted', 0),
]);
}
public function show(Contract $contract)
{
return inertia('Contract/Show', [
'contract' => $contract::with(['type', 'client', 'debtor'])->findOrFail($contract->id),
]);
}
public function store(Request $request)
{
$uuid = $request->input('client_case_uuid');
$clientCase = \App\Models\ClientCase::where('uuid', $uuid)->firstOrFail();
if (isset($clientCase->id)) {
\DB::transaction(function () use ($request, $clientCase) {
// Create contract
$clientCase->contracts()->create([
'reference' => $request->input('reference'),
'start_date' => date('Y-m-d', strtotime($request->input('start_date'))),
'type_id' => $request->input('type_id'),
]);
});
}
return to_route('clientCase.show', $clientCase);
}
public function update(Contract $contract, Request $request)
{
$contract->update([
'referenca' => $request->input('referenca'),
'type_id' => $request->input('type_id'),
]);
}
}