Fix Create

This commit is contained in:
R
2022-11-15 11:07:43 +07:00
parent 897a531326
commit f71eb71cfc
2 changed files with 8 additions and 7 deletions

View File

@@ -38,10 +38,8 @@ class PersonController extends Controller
* @param Request $request
* @return Renderable
*/
public function store(Request $request)
public function store(PersonRequest $request)
{
$request->validate([]);
$personData = $request->only([
'owner_user_id',
'nik',
@@ -70,9 +68,12 @@ class PersonController extends Controller
'owner_user_id' => auth()->user()->id,
]);
$personModel = Person::query()->create($personData);
$person = Person::query()->create($personData);
auth()->user()->person->families()->attach($person, [
'relation_with_owner' => $request->relation_with_owner
]);
return Helper::responseJson(['persons' => new PersonResource($personModel)], Response::HTTP_CREATED, 'Data berhasil di buat');
return Helper::responseJson(['persons' => new PersonResource($person)], Response::HTTP_CREATED, 'Data berhasil di buat');
}
/**

View File

@@ -28,8 +28,8 @@ class PersonResource extends JsonResource
'phone' => $this->phone,
'email' => $this->email,
'blood_type' => $this->blood_type,
'weight' => (float) $this->last_weight_kg,
'height' => (float) $this->last_height_cm,
'weight' => !empty($this->last_weight_kg) ? (float) $this->last_weight_kg : null,
'height' => !empty($this->last_weight_kg) ? (float) $this->last_height_cm : null,
'relation_with_owner' => ($this->user && $this->user->person_id == $this->id) ? 'Self' : $this->pivot->relation_with_owner ?? null,
'marital_status' => $this->marital_status,
'last_education' => $this->last_education,