Fix Create
This commit is contained in:
@@ -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');
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user