api person create & update & add family
This commit is contained in:
@@ -29,6 +29,16 @@ class AuthController extends Controller
|
|||||||
'otp' => rand(1000, 9999),
|
'otp' => rand(1000, 9999),
|
||||||
'otp_created_at' => now()
|
'otp_created_at' => now()
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
$person = Person::query()->create([
|
||||||
|
'owner_user_id' => $user->id,
|
||||||
|
'email' => $request->phone_or_email,
|
||||||
|
'created_by' => $user->id,
|
||||||
|
]);
|
||||||
|
|
||||||
|
User::query()->find($user->id)->update([
|
||||||
|
'person_id' => $person->id
|
||||||
|
]);
|
||||||
} else {
|
} else {
|
||||||
$user = User::updateOrCreate([
|
$user = User::updateOrCreate([
|
||||||
'phone' => $request->phone_or_email
|
'phone' => $request->phone_or_email
|
||||||
@@ -37,6 +47,16 @@ class AuthController extends Controller
|
|||||||
'otp' => rand(1000, 9999),
|
'otp' => rand(1000, 9999),
|
||||||
'otp_created_at' => now()
|
'otp_created_at' => now()
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
$person = Person::query()->create([
|
||||||
|
'owner_user_id' => $user->id,
|
||||||
|
'phone' => $request->phone_or_email,
|
||||||
|
'created_by' => $user->id,
|
||||||
|
]);
|
||||||
|
|
||||||
|
User::query()->find($user->id)->update([
|
||||||
|
'person_id' => $person->id
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$user) {
|
if (!$user) {
|
||||||
@@ -57,6 +77,7 @@ class AuthController extends Controller
|
|||||||
return response()->json([
|
return response()->json([
|
||||||
'message' => 'OTP Terkirim',
|
'message' => 'OTP Terkirim',
|
||||||
'data' => [
|
'data' => [
|
||||||
|
'otp' => $user->otp,
|
||||||
'otp_valid_until' => $user->otp_created_at->addMinutes(config('linksehat.otp_valid_minutes'))
|
'otp_valid_until' => $user->otp_created_at->addMinutes(config('linksehat.otp_valid_minutes'))
|
||||||
]
|
]
|
||||||
]);
|
]);
|
||||||
@@ -181,16 +202,11 @@ class AuthController extends Controller
|
|||||||
return Socialite::driver($provider)->redirect();
|
return Socialite::driver($provider)->redirect();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function handleSocialLoginCallback(Request $request, $provider)
|
public function handleSocialLoginCallback($provider)
|
||||||
{
|
{
|
||||||
// get the provider's user. (In the provider server)
|
$providerUser = Socialite::driver($provider)->stateless()->user();
|
||||||
$providerUser = Socialite::driver($provider)->user();
|
$user = User::query()->firstWhere('email', $providerUser->email);
|
||||||
|
|
||||||
// check if access token exists etc..
|
|
||||||
// search for a user in our server with the specified provider id and provider name
|
|
||||||
$user = User::where('email', $providerUser->email)->first();
|
|
||||||
|
|
||||||
// // if there is no record with these data, create a new user
|
|
||||||
if (!$user) {
|
if (!$user) {
|
||||||
$user = User::query()->create([
|
$user = User::query()->create([
|
||||||
'email' => $providerUser->email,
|
'email' => $providerUser->email,
|
||||||
@@ -200,6 +216,7 @@ class AuthController extends Controller
|
|||||||
'owner_user_id' => $user->id,
|
'owner_user_id' => $user->id,
|
||||||
'name' => $providerUser->name,
|
'name' => $providerUser->name,
|
||||||
'email' => $providerUser->email,
|
'email' => $providerUser->email,
|
||||||
|
'created_by' => $user->id,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
User::query()->find($user->id)->update([
|
User::query()->find($user->id)->update([
|
||||||
@@ -207,7 +224,6 @@ class AuthController extends Controller
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// // return the token for usage
|
|
||||||
return response([
|
return response([
|
||||||
'message' => 'Selamat Datang',
|
'message' => 'Selamat Datang',
|
||||||
'user' => UserProfileResource::make($user),
|
'user' => UserProfileResource::make($user),
|
||||||
|
|||||||
@@ -2,11 +2,14 @@
|
|||||||
|
|
||||||
namespace Modules\Linksehat\Http\Controllers\Api;
|
namespace Modules\Linksehat\Http\Controllers\Api;
|
||||||
|
|
||||||
use App\Models\PractitionerRole;
|
use App\Models\File;
|
||||||
|
use App\Models\Person;
|
||||||
use Illuminate\Contracts\Support\Renderable;
|
use Illuminate\Contracts\Support\Renderable;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Routing\Controller;
|
use Illuminate\Routing\Controller;
|
||||||
use Modules\Linksehat\Transformers\Speciality\SpecialityResource;
|
use Modules\Linksehat\Http\Requests\PersonRequest;
|
||||||
|
use Modules\Linksehat\Transformers\Person\PersonResource;
|
||||||
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
|
|
||||||
class PersonController extends Controller
|
class PersonController extends Controller
|
||||||
{
|
{
|
||||||
@@ -14,69 +17,11 @@ class PersonController extends Controller
|
|||||||
* Display a listing of the resource.
|
* Display a listing of the resource.
|
||||||
* @return Renderable
|
* @return Renderable
|
||||||
*/
|
*/
|
||||||
public function index(Request $request)
|
public function index()
|
||||||
{
|
{
|
||||||
$organizationId = $request->organization_id;
|
$personModel = Person::query()->with('avatar')->where('owner_user_id', auth()->user()->id)->get();
|
||||||
$specialityId = $request->speciality_id;
|
|
||||||
|
|
||||||
if (empty($organizationId) || empty($specialityId)) {
|
return $personModel;
|
||||||
$messageorganizationId = !empty($organizationId) ? ' ' : ' organization_id or ';
|
|
||||||
$messageSpecialityId = !empty($specialityId) ? ' ' : 'speciality_id';
|
|
||||||
|
|
||||||
abort(400, 'missing parameter' . $messageorganizationId . $messageSpecialityId);
|
|
||||||
}
|
|
||||||
|
|
||||||
$doctors = PractitionerRole::query()->with(['practitioner.person', 'speciality'])->where('organization_id', $organizationId)->where('speciality_id', $specialityId)->get();
|
|
||||||
|
|
||||||
foreach ($doctors as $key => $doctor) {
|
|
||||||
$specialisName = $doctor->speciality->name;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Price belum ke ambil
|
|
||||||
return response()->json([
|
|
||||||
'status' => true,
|
|
||||||
'statusCode' => 200,
|
|
||||||
'message' => 'Data Berhasil di ambil',
|
|
||||||
'data' => [
|
|
||||||
'title' => 'Spesialis ' . $specialisName,
|
|
||||||
'doctors' => SpecialityResource::collection($doctors)
|
|
||||||
]
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function searchSpecialityOrPerson(Request $request)
|
|
||||||
{
|
|
||||||
$doctors = PractitionerRole::query()
|
|
||||||
->with(['practitioner.person', 'speciality'])
|
|
||||||
->whereHas('practitioner.person', function ($query) use ($request) {
|
|
||||||
$query->where('name', 'LIKE', "%{$request->value}%");
|
|
||||||
})
|
|
||||||
// ->whereHas('speciality', function ($query) use ($request) {
|
|
||||||
// $query->where('name', 'LIKE', "%{$request->value}%");
|
|
||||||
// })
|
|
||||||
->get();
|
|
||||||
|
|
||||||
return $doctors;
|
|
||||||
|
|
||||||
// Price belum ke ambil
|
|
||||||
// return response()->json([
|
|
||||||
// 'status' => true,
|
|
||||||
// 'statusCode' => 200,
|
|
||||||
// 'message' => 'Data Berhasil di ambil',
|
|
||||||
// 'data' => [
|
|
||||||
// 'title' => 'Spesialis ' . $specialisName,
|
|
||||||
// 'doctors' => SpecialityResource::collection($doctors)
|
|
||||||
// ]
|
|
||||||
// ]);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Show the form for creating a new resource.
|
|
||||||
* @return Renderable
|
|
||||||
*/
|
|
||||||
public function create()
|
|
||||||
{
|
|
||||||
//
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -84,9 +29,21 @@ class PersonController extends Controller
|
|||||||
* @param Request $request
|
* @param Request $request
|
||||||
* @return Renderable
|
* @return Renderable
|
||||||
*/
|
*/
|
||||||
public function store(Request $request)
|
public function store()
|
||||||
{
|
{
|
||||||
//
|
$personModel = Person::query()->create([
|
||||||
|
'owner_user_id' => auth()->user()->id,
|
||||||
|
'created_by' => auth()->user()->id,
|
||||||
|
]);
|
||||||
|
|
||||||
|
return response()->json([
|
||||||
|
'status' => 'success',
|
||||||
|
'statusCode' => Response::HTTP_CREATED,
|
||||||
|
'message' => 'Data Berhasil di buat',
|
||||||
|
'data' => [
|
||||||
|
'person' => $personModel,
|
||||||
|
],
|
||||||
|
], Response::HTTP_CREATED);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -94,19 +51,16 @@ class PersonController extends Controller
|
|||||||
* @param int $id
|
* @param int $id
|
||||||
* @return Renderable
|
* @return Renderable
|
||||||
*/
|
*/
|
||||||
public function show(Request $request, $id)
|
public function show(Person $person)
|
||||||
{
|
{
|
||||||
//
|
return response()->json([
|
||||||
}
|
'status' => 'success',
|
||||||
|
'statusCode' => Response::HTTP_OK,
|
||||||
/**
|
'message' => 'Data Person dengan nama ' . $person->name . ' berhasil di ambil',
|
||||||
* Show the form for editing the specified resource.
|
'data' => [
|
||||||
* @param int $id
|
'person' => new PersonResource($person),
|
||||||
* @return Renderable
|
],
|
||||||
*/
|
]);
|
||||||
public function edit($id)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -115,9 +69,55 @@ class PersonController extends Controller
|
|||||||
* @param int $id
|
* @param int $id
|
||||||
* @return Renderable
|
* @return Renderable
|
||||||
*/
|
*/
|
||||||
public function update(Request $request, $id)
|
public function update(PersonRequest $request, Person $person)
|
||||||
{
|
{
|
||||||
//
|
$person->update($request->validated());
|
||||||
|
|
||||||
|
if ($request->hasFile('user_avatar')) {
|
||||||
|
$pathFileAvatar = File::storeFile('avatar', $person->id, $request->file('user_avatar'));
|
||||||
|
$person->files()->updateOrCreate([
|
||||||
|
'type' => 'avatar',
|
||||||
|
'name' => File::getFileName('avatar', $person->id, $request->file('user_avatar')),
|
||||||
|
'extension' => $request->file('user_avatar')->getClientOriginalExtension(),
|
||||||
|
'path' => $pathFileAvatar,
|
||||||
|
'created_by' => auth()->user()->id,
|
||||||
|
'updated_by' => auth()->user()->id,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($request->hasFile('verification_file')) {
|
||||||
|
$pathFileVerification = File::storeFile('dataDiri', $person->id, $request->file('verification_file'));
|
||||||
|
$person->files()->updateOrCreate([
|
||||||
|
'type' => 'dataDiri',
|
||||||
|
'name' => File::getFileName('dataDiri', $person->id, $request->file('verification_file')),
|
||||||
|
'extension' => $request->file('verification_file')->getClientOriginalExtension(),
|
||||||
|
'path' => $pathFileVerification,
|
||||||
|
'created_by' => auth()->user()->id,
|
||||||
|
'updated_by' => auth()->user()->id,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($request->has('relation_with_owner')) {
|
||||||
|
$person->familyOwner()->updateOrCreate([
|
||||||
|
'owner_id' => auth()->user()->person_id,
|
||||||
|
'person_id' => $person->id,
|
||||||
|
], [
|
||||||
|
'owner_id' => auth()->user()->person_id,
|
||||||
|
'relation_with_owner' => $request->relation_with_owner,
|
||||||
|
'person_id' => $person->id,
|
||||||
|
'created_by' => auth()->user()->id,
|
||||||
|
'updated_by' => auth()->user()->id,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return response()->json([
|
||||||
|
'status' => 'success',
|
||||||
|
'statusCode' => Response::HTTP_OK,
|
||||||
|
'message' => 'Data Berhasil di update',
|
||||||
|
'data' => [
|
||||||
|
'person' => $person,
|
||||||
|
],
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
65
Modules/Linksehat/Http/Requests/PersonRequest.php
Normal file
65
Modules/Linksehat/Http/Requests/PersonRequest.php
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Modules\Linksehat\Http\Requests;
|
||||||
|
|
||||||
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
|
|
||||||
|
class PersonRequest extends FormRequest
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Determine if the user is authorized to make this request.
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function authorize()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the validation rules that apply to the request.
|
||||||
|
*
|
||||||
|
* @return array<string, mixed>
|
||||||
|
*/
|
||||||
|
public function rules()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'name' => 'string',
|
||||||
|
'birth_place' => 'string',
|
||||||
|
'birth_date' => 'date',
|
||||||
|
'gender' => 'string',
|
||||||
|
'phone' => 'numeric',
|
||||||
|
'email' => 'email',
|
||||||
|
'blood_type' => 'string',
|
||||||
|
'weight' => 'string',
|
||||||
|
'height' => 'string',
|
||||||
|
'relation_with_owner' => 'string', // relasi family table
|
||||||
|
'marital_status' => 'string',
|
||||||
|
'religion' => 'string',
|
||||||
|
'last_education' => 'string',
|
||||||
|
'current_employment' => 'string',
|
||||||
|
'nik' => 'string|min:16|max:16',
|
||||||
|
'updated_by' => 'integer',
|
||||||
|
'user_avatar' => 'file', // relasi file table
|
||||||
|
'verification_file' => 'file', // relasi file table
|
||||||
|
'is_ktp' => 'boolean',
|
||||||
|
'citizenship' => 'string',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Prepare the data for validation.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
protected function prepareForValidation()
|
||||||
|
{
|
||||||
|
$citizenship = $this->is_ktp ? 'wni' : 'wna';
|
||||||
|
|
||||||
|
$this->merge([
|
||||||
|
'birth_date' => empty($this->birth_date) ? $this->birth_date . " 00:00:00" : $this->birth_date,
|
||||||
|
'updated_by' => auth()->user()->id,
|
||||||
|
'citizenship' => $citizenship ? $citizenship : NULL
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,6 +4,7 @@ use Modules\Linksehat\Http\Controllers\Api\AuthController;
|
|||||||
use Modules\Linksehat\Http\Controllers\Api\DashboardController;
|
use Modules\Linksehat\Http\Controllers\Api\DashboardController;
|
||||||
use Modules\Linksehat\Http\Controllers\Api\DoctorController;
|
use Modules\Linksehat\Http\Controllers\Api\DoctorController;
|
||||||
use Modules\Linksehat\Http\Controllers\Api\HospitalController;
|
use Modules\Linksehat\Http\Controllers\Api\HospitalController;
|
||||||
|
use Modules\Linksehat\Http\Controllers\Api\PersonController;
|
||||||
use Modules\Linksehat\Http\Controllers\Api\ProfileController;
|
use Modules\Linksehat\Http\Controllers\Api\ProfileController;
|
||||||
use Modules\Linksehat\Http\Controllers\Api\SpecialityController;
|
use Modules\Linksehat\Http\Controllers\Api\SpecialityController;
|
||||||
|
|
||||||
@@ -51,5 +52,6 @@ Route::prefix('linksehat')->group(function () {
|
|||||||
Route::middleware('auth:sanctum')->group(function () {
|
Route::middleware('auth:sanctum')->group(function () {
|
||||||
Route::get('profile', [ProfileController::class, 'index'])->name('profile');
|
Route::get('profile', [ProfileController::class, 'index'])->name('profile');
|
||||||
Route::post('profile', [ProfileController::class, 'update'])->name('profile.update');
|
Route::post('profile', [ProfileController::class, 'update'])->name('profile.update');
|
||||||
|
Route::apiResource('persons', PersonController::class)->except(['destroy']);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
40
Modules/Linksehat/Transformers/Person/PersonResource.php
Normal file
40
Modules/Linksehat/Transformers/Person/PersonResource.php
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Modules\Linksehat\Transformers\Person;
|
||||||
|
|
||||||
|
use App\Helpers\Helper;
|
||||||
|
use Illuminate\Http\Resources\Json\JsonResource;
|
||||||
|
|
||||||
|
class PersonResource extends JsonResource
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Transform the resource into an array.
|
||||||
|
*
|
||||||
|
* @param \Illuminate\Http\Request
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function toArray($request)
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'avatar' => [
|
||||||
|
'title' => $this->avatar->name ?? '',
|
||||||
|
'url' => url($this->avatar->path) ?? '',
|
||||||
|
],
|
||||||
|
'id' => $this->id,
|
||||||
|
'name' => $this->name,
|
||||||
|
'birth_place' => $this->birth_place,
|
||||||
|
'gender' => $this->gender,
|
||||||
|
'phone' => $this->phone,
|
||||||
|
'email' => $this->email,
|
||||||
|
'blood_type' => $this->blood_type,
|
||||||
|
'weight' => $this->weight,
|
||||||
|
'height' => $this->height,
|
||||||
|
'relation_with_owner' => $this->relation_with_owner,
|
||||||
|
'marital_status' => $this->marital_status,
|
||||||
|
'last_education' => $this->last_education,
|
||||||
|
'current_employment' => $this->current_employment,
|
||||||
|
'nik' => $this->nik,
|
||||||
|
'religion' => $this->religion,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
22
app/Models/Family.php
Normal file
22
app/Models/Family.php
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
|
class Family extends Model
|
||||||
|
{
|
||||||
|
use HasFactory;
|
||||||
|
|
||||||
|
protected $table = 'family_relations';
|
||||||
|
|
||||||
|
protected $fillable = [
|
||||||
|
'owner_id',
|
||||||
|
'relation_with_owner',
|
||||||
|
'person_id',
|
||||||
|
'created_by',
|
||||||
|
'updated_by',
|
||||||
|
'deleted_by',
|
||||||
|
];
|
||||||
|
}
|
||||||
@@ -10,7 +10,7 @@ use Illuminate\Support\Str;
|
|||||||
class File extends Model
|
class File extends Model
|
||||||
{
|
{
|
||||||
use HasFactory;
|
use HasFactory;
|
||||||
|
|
||||||
protected $fillable = [
|
protected $fillable = [
|
||||||
'fileable_type',
|
'fileable_type',
|
||||||
'fileable_id',
|
'fileable_id',
|
||||||
@@ -20,12 +20,10 @@ class File extends Model
|
|||||||
'path',
|
'path',
|
||||||
];
|
];
|
||||||
|
|
||||||
protected $appends = [
|
|
||||||
'url'
|
|
||||||
];
|
|
||||||
|
|
||||||
public static $file_directories = [
|
public static $file_directories = [
|
||||||
'import-temp' => 'import-temp/',
|
'import-temp' => 'import-temp/',
|
||||||
|
'avatar' => 'user-avatar/',
|
||||||
|
'dataDiri' => 'data-diri/'
|
||||||
];
|
];
|
||||||
|
|
||||||
public function fileable()
|
public function fileable()
|
||||||
@@ -33,29 +31,23 @@ class File extends Model
|
|||||||
return $this->morphTo();
|
return $this->morphTo();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getUrlAttribute()
|
public static function getDirectory($type)
|
||||||
{
|
|
||||||
return Storage::url($this->path);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getDirectory($type)
|
|
||||||
{
|
{
|
||||||
return self::$file_directories[$type] ?? 'any';
|
return self::$file_directories[$type] ?? 'any';
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getFileName($type, $id, $file)
|
public static function getFileName($type, $id)
|
||||||
{
|
{
|
||||||
$extension = $file->getClientOriginalExtension();
|
return $type . '-' . $id . '-' . Str::random(10);
|
||||||
|
|
||||||
return $type . '-' . $id .'-'.Str::random(10).'.'.$extension;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function storeFile($type, $id, $file)
|
public static function storeFile($type, $id, $file)
|
||||||
{
|
{
|
||||||
$fileName = self::getFileName($type, $id, $file);
|
$fileName = self::getFileName($type, $id);
|
||||||
$directory = self::getDirectory($type);
|
$directory = self::getDirectory($type);
|
||||||
$path = $directory . $fileName;
|
$extension = $file->getClientOriginalExtension();
|
||||||
$file->storeAs($directory, $fileName);
|
$path = $directory . $fileName . '.' . $extension;
|
||||||
|
$file->storeAs('public/' . $directory, $fileName . '.' . $extension);
|
||||||
return $path;
|
return $path;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,20 +10,33 @@ class Person extends Model
|
|||||||
use HasFactory;
|
use HasFactory;
|
||||||
|
|
||||||
protected $table = 'persons';
|
protected $table = 'persons';
|
||||||
|
|
||||||
protected $fillable = [
|
protected $fillable = [
|
||||||
'owner_user_id',
|
'owner_user_id',
|
||||||
'nik',
|
'nik',
|
||||||
'name_prefix',
|
'name_prefix',
|
||||||
'name',
|
'name',
|
||||||
'name_suffix',
|
'name_suffix',
|
||||||
|
'phone',
|
||||||
|
'email',
|
||||||
'gender',
|
'gender',
|
||||||
'birth_date',
|
'birth_date',
|
||||||
|
'birth_place',
|
||||||
|
'citizenship',
|
||||||
|
'current_employment',
|
||||||
|
'last_education',
|
||||||
|
'religion',
|
||||||
|
'blood_type',
|
||||||
|
'weight',
|
||||||
|
'height',
|
||||||
'is_deceased',
|
'is_deceased',
|
||||||
'deceased_at',
|
'deceased_at',
|
||||||
'marital_status',
|
'marital_status',
|
||||||
'main_address_id',
|
'main_address_id',
|
||||||
'domicile_address_id',
|
'domicile_address_id',
|
||||||
|
'created_by',
|
||||||
|
'updated_by',
|
||||||
|
'deleted_by'
|
||||||
];
|
];
|
||||||
|
|
||||||
public function getFullNameAttribute()
|
public function getFullNameAttribute()
|
||||||
@@ -31,11 +44,11 @@ class Person extends Model
|
|||||||
$arr = [];
|
$arr = [];
|
||||||
if (!empty($this->name_prefix)) {
|
if (!empty($this->name_prefix)) {
|
||||||
$arr[] = $this->name_prefix;
|
$arr[] = $this->name_prefix;
|
||||||
}
|
}
|
||||||
$arr[] = $this->name;
|
$arr[] = $this->name;
|
||||||
if (!empty($this->name_suffix)) {
|
if (!empty($this->name_suffix)) {
|
||||||
$arr[] = $this->name_suffix;
|
$arr[] = $this->name_suffix;
|
||||||
}
|
}
|
||||||
|
|
||||||
return implode(' ', $arr);
|
return implode(' ', $arr);
|
||||||
}
|
}
|
||||||
@@ -44,17 +57,17 @@ class Person extends Model
|
|||||||
{
|
{
|
||||||
return $this->morphMany(Address::class, 'addressable');
|
return $this->morphMany(Address::class, 'addressable');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function currentAddress()
|
public function currentAddress()
|
||||||
{
|
{
|
||||||
return $this->belongsTo(Address::class, 'main_address_id');
|
return $this->belongsTo(Address::class, 'main_address_id');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function domicileAddress()
|
public function domicileAddress()
|
||||||
{
|
{
|
||||||
return $this->belongsTo(Address::class, 'main_address_id');
|
return $this->belongsTo(Address::class, 'main_address_id');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function metas()
|
public function metas()
|
||||||
{
|
{
|
||||||
return $this->morphMany(Meta::class, 'metaable');
|
return $this->morphMany(Meta::class, 'metaable');
|
||||||
@@ -65,26 +78,18 @@ class Person extends Model
|
|||||||
return $this->belongsTo(User::class, 'owner_user_id');
|
return $this->belongsTo(User::class, 'owner_user_id');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function makeLmsApiData()
|
public function files()
|
||||||
{
|
{
|
||||||
return [
|
return $this->morphMany(File::class, 'fileable');
|
||||||
'name' => $this->name,
|
}
|
||||||
'birth_date' => $this->birth_date,
|
|
||||||
'birth_place' => $this->birth_place,
|
public function avatar()
|
||||||
'gender' => $this->gender,
|
{
|
||||||
'blood_type' => $this->blood_type,
|
return $this->morphOne(File::class, 'fileable')->where('type', 'avatar')->latestOfMany();
|
||||||
'religion' => $this->religion,
|
}
|
||||||
'last_education' => $this->last_education,
|
|
||||||
'current_employment' => $this->current_employment,
|
public function familyOwner()
|
||||||
'marital_status' => $this->marital_status,
|
{
|
||||||
'nik' => $this->nik,
|
return $this->hasOne(Family::class, 'person_id');
|
||||||
'citizenship' => $this->citizenship,
|
|
||||||
'address' => $this->currentAddress->text ?? null,
|
|
||||||
'city_name' => $this->currentAddress->city->name ?? null,
|
|
||||||
'domicile_address' => $this->domicileAddress->text ?? null,
|
|
||||||
'domicile_city_name' => $this->domicileAddress->city->name ?? null,
|
|
||||||
'email' => $this->email,
|
|
||||||
'phone' => $this->phone,
|
|
||||||
];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,37 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
Schema::create('family_relations', function (Blueprint $table) {
|
||||||
|
$table->id();
|
||||||
|
$table->string('relation_with_owner');
|
||||||
|
$table->timestamps();
|
||||||
|
$table->softDeletes();
|
||||||
|
|
||||||
|
$table->foreignId('created_by')->nullable();
|
||||||
|
$table->foreignId('updated_by')->nullable();
|
||||||
|
$table->foreignId('deleted_by')->nullable();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
Schema::dropIfExists('family_relations');
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
Schema::table('family_relations', function (Blueprint $table) {
|
||||||
|
$table->foreignId('owner_id')->nullable()->after('id');
|
||||||
|
$table->foreignId('person_id')->nullable()->after('relation_with_owner');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
Schema::table('family_relations', function (Blueprint $table) {
|
||||||
|
$table->dropColumn('owner_id');
|
||||||
|
$table->dropColumn('person_id');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user