Teren-app/app/Http/Controllers/PersonController.php
Simon Pocrnjič 0f8cfd3f16 changes
2025-01-02 18:38:47 +01:00

111 lines
3.2 KiB
PHP

<?php
namespace App\Http\Controllers;
use App\Models\Person\Person;
use Illuminate\Http\Request;
use Inertia\Inertia;
class PersonController extends Controller
{
//
public function show(Person $person){
}
public function create(Request $request){
}
public function store(Request $request){
}
public function update(Person $person, Request $request){
$attributes = $request->validate([
'full_name' => 'string|max:255',
'tax_number' => 'nullable|integer',
'social_security_number' => 'nullable|integer',
'description' => 'nullable|string|max:500'
]);
$person->update($attributes);
return response()->json([
'person' => [
'full_name' => $person->full_name,
'tax_number' => $person->tax_number,
'social_security_number' => $person->social_security_number,
'description' => $person->description
]
]);
}
public function createAddress(Person $person, Request $request){
$attributes = $request->validate([
'address' => 'required|string|max:150',
'country' => 'nullable|string',
'type_id' => 'required|integer|exists:address_types,id',
'description' => 'nullable|string|max:125'
]);
$address_id = $person->addresses()->create($attributes)->id;
return response()->json([
'address' => \App\Models\Person\PersonAddress::with(['type'])->findOrFail($address_id)
]);
}
public function updateAddress(Person $person, int $address_id, Request $request)
{
$attributes = $request->validate([
'address' => 'required|string|max:150',
'country' => 'nullable|string',
'type_id' => 'required|integer|exists:address_types,id',
'description' => 'nullable|string|max:125'
]);
$address = $person->addresses()->with(['type'])->findOrFail($address_id);
$address->update($attributes);
return response()->json([
'address' => $address
]);
}
public function createPhone(Person $person, Request $request)
{
$attributes = $request->validate([
'nu' => 'required|string|max:50',
'country_code' => 'nullable|integer',
'type_id' => 'required|integer|exists:phone_types,id',
'description' => 'nullable|string|max:125'
]);
$phone_id = $person->phones()->create($attributes)->id;
return response()->json([
'phone' => \App\Models\Person\PersonPhone::with(['type'])->findOrFail($phone_id)
]);
}
public function updatePhone(Person $person, int $phone_id, Request $request)
{
$attributes = $request->validate([
'nu' => 'required|string|max:50',
'country_code' => 'nullable|integer',
'type_id' => 'required|integer|exists:phone_types,id',
'description' => 'nullable|string|max:125'
]);
$phone = $person->phones()->with(['type'])->findOrFail($phone_id);
$phone->update($attributes);
return response()->json([
'phone' => $phone
]);
}
}