Add Json Response Helper

This commit is contained in:
R
2022-11-02 21:48:14 +07:00
parent 429dc476e2
commit 9a7f26928f
3 changed files with 15 additions and 4 deletions

View File

@@ -61,10 +61,7 @@ class DoctorController extends Controller
$doctors = $doctors->paginate($limit);
return response()->json([
'message' => 'Sukses mengambil data Dokter',
'doctors' => Helper::paginateResources(PractitionerRoleToDoctorResource::collection($doctors))
]);
return Helper::makeJsonResponse(Helper::paginateResources(PractitionerRoleToDoctorResource::collection($doctors)));
}
/**

View File

@@ -147,4 +147,13 @@ class Helper
{
return "Rp. " . number_format($price, 0, ',', '.');
}
public static function makeJsonResponse($data, $statusCode = 200, $message = "Data berhasil diambil")
{
return response()->json([
'statusCode' => $statusCode,
'message' => $message,
'data' => $data
], $statusCode);
}
}

View File

@@ -79,4 +79,9 @@ class User extends Authenticatable
{
return $this->belongsTo(Person::class, 'person_id');
}
public function ownedPersons()
{
return $this->hasMany(Person::class, 'owner_user_id');
}
}