DONE: layout letter with letterhead and footer, notification for newly...
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\User\Http\Controllers;
|
||||
|
||||
use App\Http\Controllers\BaseCrudController;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Modules\User\Entities\Address;
|
||||
use Modules\User\Http\Requests\AddressRequest;
|
||||
use Modules\User\Repositories\Contracts\AddressRepositoryInterface;
|
||||
use Modules\User\Transformers\AddressResource;
|
||||
|
||||
class AddressController extends BaseCrudController
|
||||
{
|
||||
protected $modelClass = Address::class;
|
||||
|
||||
protected $resourceClass = AddressResource::class;
|
||||
|
||||
protected $requestClass = AddressRequest::class;
|
||||
|
||||
protected $resourceName = 'address';
|
||||
|
||||
protected $resourceNamePlural = 'addresses';
|
||||
|
||||
public function __construct(
|
||||
AddressRepositoryInterface $addressRepository,
|
||||
) {
|
||||
parent::__construct($addressRepository);
|
||||
}
|
||||
|
||||
protected function prepareStoreData(array $validated): array
|
||||
{
|
||||
return array_merge($validated, [
|
||||
'user_id' => auth()->id(),
|
||||
]);
|
||||
}
|
||||
|
||||
protected function getItemName($item): string
|
||||
{
|
||||
return $item->address_type ?? $item->id;
|
||||
}
|
||||
|
||||
protected function prepareUpdateData(array $validated, $address): array
|
||||
{
|
||||
return $validated;
|
||||
}
|
||||
|
||||
protected function checkDependencies($address): ?JsonResponse
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\User\Http\Controllers;
|
||||
|
||||
use App\Http\Controllers\BaseCrudController;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Modules\User\Entities\Bank;
|
||||
use Modules\User\Http\Requests\BankRequest;
|
||||
use Modules\User\Repositories\Contracts\BankRepositoryInterface;
|
||||
use Modules\User\Transformers\BankResource;
|
||||
|
||||
class BankController extends BaseCrudController
|
||||
{
|
||||
protected $modelClass = Bank::class;
|
||||
|
||||
protected $resourceClass = BankResource::class;
|
||||
|
||||
protected $requestClass = BankRequest::class;
|
||||
|
||||
protected $resourceName = 'bank';
|
||||
|
||||
protected $resourceNamePlural = 'banks';
|
||||
|
||||
public function __construct(
|
||||
BankRepositoryInterface $bankRepository,
|
||||
) {
|
||||
parent::__construct($bankRepository);
|
||||
}
|
||||
|
||||
protected function prepareStoreData(array $validated): array
|
||||
{
|
||||
return $validated;
|
||||
}
|
||||
|
||||
protected function getItemName($item): string
|
||||
{
|
||||
return $item->name ?? $item->id;
|
||||
}
|
||||
|
||||
protected function prepareUpdateData(array $validated, $bank): array
|
||||
{
|
||||
return $validated;
|
||||
}
|
||||
|
||||
protected function checkDependencies($bank): ?JsonResponse
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public function active(): JsonResponse
|
||||
{
|
||||
$banks = $this->repository->active();
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'data' => $this->resourceClass::collection($banks),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\User\Http\Controllers;
|
||||
|
||||
use App\Http\Controllers\BaseCrudController;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Modules\User\Entities\BankDetail;
|
||||
use Modules\User\Http\Requests\BankDetailRequest;
|
||||
use Modules\User\Repositories\Contracts\BankDetailRepositoryInterface;
|
||||
use Modules\User\Transformers\BankDetailResource;
|
||||
|
||||
class BankDetailController extends BaseCrudController
|
||||
{
|
||||
protected $modelClass = BankDetail::class;
|
||||
|
||||
protected $resourceClass = BankDetailResource::class;
|
||||
|
||||
protected $requestClass = BankDetailRequest::class;
|
||||
|
||||
protected $resourceName = 'bank_detail';
|
||||
|
||||
protected $resourceNamePlural = 'bank_details';
|
||||
|
||||
public function __construct(
|
||||
BankDetailRepositoryInterface $bankDetailRepository,
|
||||
) {
|
||||
parent::__construct($bankDetailRepository);
|
||||
}
|
||||
|
||||
protected function prepareStoreData(array $validated): array
|
||||
{
|
||||
return array_merge($validated, [
|
||||
'user_id' => auth()->id(),
|
||||
]);
|
||||
}
|
||||
|
||||
protected function getItemName($item): string
|
||||
{
|
||||
return $item->account_number ?? $item->id;
|
||||
}
|
||||
|
||||
protected function prepareUpdateData(array $validated, $bankDetail): array
|
||||
{
|
||||
return $validated;
|
||||
}
|
||||
|
||||
protected function checkDependencies($bankDetail): ?JsonResponse
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\User\Http\Controllers;
|
||||
|
||||
use App\Http\Controllers\BaseCrudController;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Modules\User\Entities\Employment;
|
||||
use Modules\User\Http\Requests\EmploymentRequest;
|
||||
use Modules\User\Repositories\Contracts\EmploymentRepositoryInterface;
|
||||
use Modules\User\Transformers\EmploymentResource;
|
||||
|
||||
class EmploymentController extends BaseCrudController
|
||||
{
|
||||
protected $modelClass = Employment::class;
|
||||
|
||||
protected $resourceClass = EmploymentResource::class;
|
||||
|
||||
protected $requestClass = EmploymentRequest::class;
|
||||
|
||||
protected $resourceName = 'employment';
|
||||
|
||||
protected $resourceNamePlural = 'employments';
|
||||
|
||||
public function __construct(
|
||||
EmploymentRepositoryInterface $employmentRepository,
|
||||
) {
|
||||
parent::__construct($employmentRepository);
|
||||
}
|
||||
|
||||
protected function prepareStoreData(array $validated): array
|
||||
{
|
||||
return array_merge($validated, [
|
||||
'user_id' => auth()->id(),
|
||||
]);
|
||||
}
|
||||
|
||||
protected function getItemName($item): string
|
||||
{
|
||||
return $item->company_name ?? $item->id;
|
||||
}
|
||||
|
||||
protected function prepareUpdateData(array $validated, $employment): array
|
||||
{
|
||||
return $validated;
|
||||
}
|
||||
|
||||
protected function checkDependencies($employment): ?JsonResponse
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\User\Http\Controllers;
|
||||
|
||||
use App\Http\Controllers\BaseCrudController;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Modules\User\Entities\Heir;
|
||||
use Modules\User\Http\Requests\HeirRequest;
|
||||
use Modules\User\Repositories\Contracts\HeirRepositoryInterface;
|
||||
use Modules\User\Transformers\HeirResource;
|
||||
|
||||
class HeirController extends BaseCrudController
|
||||
{
|
||||
protected $modelClass = Heir::class;
|
||||
|
||||
protected $resourceClass = HeirResource::class;
|
||||
|
||||
protected $requestClass = HeirRequest::class;
|
||||
|
||||
protected $resourceName = 'heir';
|
||||
|
||||
protected $resourceNamePlural = 'heirs';
|
||||
|
||||
public function __construct(
|
||||
HeirRepositoryInterface $heirRepository,
|
||||
) {
|
||||
parent::__construct($heirRepository);
|
||||
}
|
||||
|
||||
protected function prepareStoreData(array $validated): array
|
||||
{
|
||||
return array_merge($validated, [
|
||||
'user_id' => auth()->id(),
|
||||
]);
|
||||
}
|
||||
|
||||
protected function getItemName($item): string
|
||||
{
|
||||
return $item->name ?? $item->id;
|
||||
}
|
||||
|
||||
protected function prepareUpdateData(array $validated, $heir): array
|
||||
{
|
||||
return $validated;
|
||||
}
|
||||
|
||||
protected function checkDependencies($heir): ?JsonResponse
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace Modules\User\Http\Controllers;
|
||||
|
||||
use App\Http\Controllers\BaseCrudController;
|
||||
use App\Services\ActivityLogger;
|
||||
use Exception;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
@@ -13,7 +14,7 @@ use Modules\Auth\Entities\User;
|
||||
use Modules\User\Http\Requests\UserRequest;
|
||||
use Modules\User\Repositories\Contracts\UserRepositoryInterface;
|
||||
use Modules\User\Services\UserService;
|
||||
use Modules\User\Transformers\UserResource;
|
||||
use Modules\Auth\Transformers\UserResource;
|
||||
use Modules\User\Transformers\UserListResource;
|
||||
|
||||
class UserController extends BaseCrudController
|
||||
@@ -104,6 +105,13 @@ class UserController extends BaseCrudController
|
||||
'phone_number' => 'sometimes|string|max:255',
|
||||
'image' => 'sometimes|image|mimes:jpeg,png,jpg,gif|max:2048',
|
||||
'image_url' => 'sometimes|string|max:255',
|
||||
'gender' => 'sometimes|string|max:255',
|
||||
'marriage_status' => 'sometimes|string|max:255',
|
||||
'member_number' => 'sometimes|integer',
|
||||
'member_type' => 'sometimes|string|max:255',
|
||||
'join_date' => 'sometimes|date',
|
||||
'birth_date' => 'sometimes|date',
|
||||
'birth_place' => 'sometimes|string|max:255',
|
||||
]);
|
||||
|
||||
$user = $this->userService->updateProfile(
|
||||
@@ -182,6 +190,69 @@ class UserController extends BaseCrudController
|
||||
}
|
||||
}
|
||||
|
||||
public function deletedIndex(Request $request): JsonResponse
|
||||
{
|
||||
$this->authorize('viewAny', $this->modelClass);
|
||||
|
||||
try {
|
||||
$perPage = min((int) $request->get('per_page', 10), 500);
|
||||
$items = $this->userService->getDeletedPaginatedList(
|
||||
$perPage,
|
||||
$request->get('search', ''),
|
||||
$request->get('status', ''),
|
||||
$request->get('sort_by', 'deleted_at'),
|
||||
$request->get('sort_order', 'desc')
|
||||
);
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'data' => UserListResource::collection($items->items()),
|
||||
'pagination' => [
|
||||
'current_page' => $items->currentPage(),
|
||||
'per_page' => $items->perPage(),
|
||||
'total' => $items->total(),
|
||||
'last_page' => $items->lastPage(),
|
||||
'from' => $items->firstItem(),
|
||||
'to' => $items->lastItem(),
|
||||
'has_more_pages' => $items->hasMorePages(),
|
||||
],
|
||||
'message' => 'Deleted users retrieved successfully.',
|
||||
]);
|
||||
} catch (Exception $e) {
|
||||
Log::error("Error fetching deleted {$this->resourceNamePlural}: ".$e->getMessage());
|
||||
|
||||
return $this->errorResponse('Failed to retrieve deleted users.', 500);
|
||||
}
|
||||
}
|
||||
|
||||
public function restore(string $id): JsonResponse
|
||||
{
|
||||
$this->authorize('restore', $this->modelClass);
|
||||
|
||||
try {
|
||||
$user = $this->userService->restoreUser($id);
|
||||
|
||||
if (! $user) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Deleted user not found.',
|
||||
], 404);
|
||||
}
|
||||
|
||||
ActivityLogger::log("Restored {$this->resourceName}: {$user->name}", $user);
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'User restored successfully.',
|
||||
'data' => (new UserListResource($user))->resolve(),
|
||||
]);
|
||||
} catch (Exception $e) {
|
||||
Log::error("Error restoring {$this->resourceName}: ".$e->getMessage());
|
||||
|
||||
return $this->errorResponse('Failed to restore user.', 500);
|
||||
}
|
||||
}
|
||||
|
||||
public function show($id): JsonResponse
|
||||
{
|
||||
$this->authorize('view', $this->modelClass);
|
||||
|
||||
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\User\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class AddressRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
// Get the address ID from the route (with null check)
|
||||
$addressId = $this->route() ? $this->route('address') : null;
|
||||
|
||||
// Check if this is a create or update operation
|
||||
$isCreate = $this->isMethod('POST');
|
||||
$isUpdate = $this->isMethod('PUT') || $this->isMethod('PATCH');
|
||||
|
||||
// If this is not a POST, PUT, or PATCH request, return minimal rules
|
||||
if (! $isCreate && ! $isUpdate) {
|
||||
return [
|
||||
'address_type' => 'nullable|string|max:255',
|
||||
'address_line_1' => 'nullable|string|max:255',
|
||||
'address_line_2' => 'nullable|string|max:255',
|
||||
'city' => 'nullable|string|max:255',
|
||||
'state' => 'nullable|string|max:255',
|
||||
'postcode' => 'nullable|string|max:255',
|
||||
'country' => 'nullable|string|max:255',
|
||||
];
|
||||
}
|
||||
|
||||
// Build unique email validation rule
|
||||
$addressUniqueRule = $addressId ? 'unique:addresses,address_type,'.$addressId : 'unique:addresses,address_type';
|
||||
|
||||
// If this is an update operation, make email and password optional
|
||||
if ($isUpdate) {
|
||||
return [
|
||||
'address_type' => 'required|string|max:255',
|
||||
'address_line_1' => 'required|string|max:255',
|
||||
'address_line_2' => 'nullable|string|max:255',
|
||||
'city' => 'required|string|max:255',
|
||||
'state' => 'required|string|max:255',
|
||||
'postcode' => 'required|string|max:255',
|
||||
'country' => 'required|string|max:255',
|
||||
];
|
||||
}
|
||||
|
||||
// Default rules for create operations
|
||||
return [
|
||||
'address_type' => 'required|string|max:255',
|
||||
'address_line_1' => 'required|string|max:255',
|
||||
'address_line_2' => 'nullable|string|max:255',
|
||||
'city' => 'required|string|max:255',
|
||||
'state' => 'required|string|max:255',
|
||||
'postcode' => 'required|string|max:255',
|
||||
'country' => 'required|string|max:255',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get custom messages for validator errors.
|
||||
*/
|
||||
public function messages(): array
|
||||
{
|
||||
return [
|
||||
'address_type.required' => 'Jenis alamat diperlukan.',
|
||||
'address_type.max' => 'Jenis alamat tidak boleh melebihi 255 aksara.',
|
||||
'address_line_1.max' => 'Alamat 1 tidak boleh melebihi 255 aksara.',
|
||||
'address_line_2.max' => 'Alamat 2 tidak boleh melebihi 255 aksara.',
|
||||
'city.max' => 'Bandar tidak boleh melebihi 255 aksara.',
|
||||
'state.max' => 'Negeri tidak boleh melebihi 255 aksara.',
|
||||
'postcode.max' => 'Poskod tidak boleh melebihi 255 aksara.',
|
||||
'country.max' => 'Negara tidak boleh melebihi 255 aksara.',
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\User\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class BankDetailRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
// Check if this is a create or update operation
|
||||
$isCreate = $this->isMethod('POST');
|
||||
$isUpdate = $this->isMethod('PUT') || $this->isMethod('PATCH');
|
||||
|
||||
// If this is not a POST, PUT, or PATCH request, return minimal rules
|
||||
if (! $isCreate && ! $isUpdate) {
|
||||
return [
|
||||
'bank_id' => 'nullable|string|max:255',
|
||||
'account_name' => 'nullable|string|max:255',
|
||||
'account_number' => 'nullable|string|max:255',
|
||||
'account_type' => 'nullable|string|max:255',
|
||||
];
|
||||
}
|
||||
|
||||
// Default rules for create and update operations
|
||||
return [
|
||||
'bank_id' => 'required|string|max:255',
|
||||
'account_name' => 'required|string|max:255',
|
||||
'account_number' => 'required|string|max:255',
|
||||
'account_type' => 'required|string|max:255',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get custom messages for validator errors.
|
||||
*/
|
||||
public function messages(): array
|
||||
{
|
||||
return [
|
||||
'bank_id.required' => 'ID bank diperlukan.',
|
||||
'bank_id.string' => 'ID bank tidak sah.',
|
||||
'bank_id.max' => 'ID bank tidak boleh melebihi 255 aksara.',
|
||||
'account_name.required' => 'Nama akaun diperlukan.',
|
||||
'account_name.string' => 'Nama akaun tidak sah.',
|
||||
'account_name.max' => 'Nama akaun tidak boleh melebihi 255 aksara.',
|
||||
'account_number.required' => 'Nombor akaun diperlukan.',
|
||||
'account_number.string' => 'Nombor akaun tidak sah.',
|
||||
'account_number.max' => 'Nombor akaun tidak boleh melebihi 255 aksara.',
|
||||
'account_type.required' => 'Jenis akaun diperlukan.',
|
||||
'account_type.string' => 'Jenis akaun tidak sah.',
|
||||
'account_type.max' => 'Jenis akaun tidak boleh melebihi 255 aksara.',
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\User\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class BankRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
// Check if this is a create or update operation
|
||||
$isCreate = $this->isMethod('POST');
|
||||
$isUpdate = $this->isMethod('PUT') || $this->isMethod('PATCH');
|
||||
|
||||
// If this is not a POST, PUT, or PATCH request, return minimal rules
|
||||
if (! $isCreate && ! $isUpdate) {
|
||||
return [
|
||||
'name' => 'nullable|string|max:255',
|
||||
'code' => 'nullable|string|max:255',
|
||||
'swift_code' => 'nullable|string|max:255',
|
||||
'is_active' => 'nullable|boolean',
|
||||
];
|
||||
}
|
||||
|
||||
// If this is an update operation, make email and password optional
|
||||
if ($isUpdate) {
|
||||
return [
|
||||
'name' => 'required|string|max:255',
|
||||
'code' => 'required|string|max:255',
|
||||
'swift_code' => 'nullable|string|max:255',
|
||||
'is_active' => 'required|boolean',
|
||||
];
|
||||
}
|
||||
|
||||
// Default rules for create operations
|
||||
return [
|
||||
'name' => 'required|string|max:255',
|
||||
'code' => 'required|string|max:255',
|
||||
'swift_code' => 'nullable|string|max:255',
|
||||
'is_active' => 'required|boolean',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get custom messages for validator errors.
|
||||
*/
|
||||
public function messages(): array
|
||||
{
|
||||
return [
|
||||
'name.required' => 'Nama bank diperlukan.',
|
||||
'name.max' => 'Nama bank tidak boleh melebihi 255 aksara.',
|
||||
'code.required' => 'Kod bank diperlukan.',
|
||||
'code.max' => 'Kod bank tidak boleh melebihi 255 aksara.',
|
||||
'swift_code.max' => 'Swift code tidak boleh melebihi 255 aksara.',
|
||||
'is_active.required' => 'Status aktif diperlukan.',
|
||||
'is_active.boolean' => 'Status aktif tidak sah.',
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\User\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class EmploymentRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
// Check if this is a create or update operation
|
||||
$isCreate = $this->isMethod('POST');
|
||||
$isUpdate = $this->isMethod('PUT') || $this->isMethod('PATCH');
|
||||
|
||||
// If this is not a POST, PUT, or PATCH request, return minimal rules
|
||||
if (! $isCreate && ! $isUpdate) {
|
||||
return [
|
||||
'company_name' => 'nullable|string|max:255',
|
||||
'job_title' => 'nullable|string|max:255',
|
||||
'employment_type' => 'nullable|string|max:255',
|
||||
'salary' => 'nullable|numeric|min:0',
|
||||
'start_date' => 'nullable|date',
|
||||
'end_date' => 'nullable|date',
|
||||
'is_current' => 'nullable|boolean',
|
||||
];
|
||||
}
|
||||
|
||||
// If this is an update operation, make email and password optional
|
||||
if ($isUpdate) {
|
||||
return [
|
||||
'company_name' => 'required|string|max:255',
|
||||
'job_title' => 'required|string|max:255',
|
||||
'employment_type' => 'required|string|max:255',
|
||||
'salary' => 'required|numeric|min:0',
|
||||
'start_date' => 'required|date',
|
||||
'end_date' => 'nullable|date',
|
||||
'is_current' => 'required|boolean',
|
||||
];
|
||||
}
|
||||
|
||||
// Default rules for create operations
|
||||
return [
|
||||
'company_name' => 'required|string|max:255',
|
||||
'job_title' => 'required|string|max:255',
|
||||
'employment_type' => 'required|string|max:255',
|
||||
'salary' => 'required|numeric|min:0',
|
||||
'start_date' => 'required|date',
|
||||
'end_date' => 'nullable|date',
|
||||
'is_current' => 'required|boolean',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get custom messages for validator errors.
|
||||
*/
|
||||
public function messages(): array
|
||||
{
|
||||
return [
|
||||
'company_name.required' => 'Nama syarikat diperlukan.',
|
||||
'company_name.max' => 'Nama syarikat tidak boleh melebihi 255 aksara.',
|
||||
'job_title.required' => 'Jawatan diperlukan.',
|
||||
'job_title.max' => 'Jawatan tidak boleh melebihi 255 aksara.',
|
||||
'employment_type.required' => 'Jenis kerja diperlukan.',
|
||||
'employment_type.max' => 'Jenis kerja tidak boleh melebihi 255 aksara.',
|
||||
'salary.required' => 'Gaji diperlukan.',
|
||||
'salary.numeric' => 'Gaji tidak sah.',
|
||||
'salary.min' => 'Gaji tidak boleh kurang dari 0.',
|
||||
'start_date.required' => 'Tarikh mulai kerja diperlukan.',
|
||||
'start_date.date' => 'Tarikh mulai kerja tidak sah.',
|
||||
'end_date.date' => 'Tarikh akhir kerja tidak sah.',
|
||||
'is_current.required' => 'Status kerja saat ini diperlukan.',
|
||||
'is_current.boolean' => 'Status kerja saat ini tidak sah.',
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\User\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class HeirRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
// Check if this is a create or update operation
|
||||
$isCreate = $this->isMethod('POST');
|
||||
$isUpdate = $this->isMethod('PUT') || $this->isMethod('PATCH');
|
||||
|
||||
// If this is not a POST, PUT, or PATCH request, return minimal rules
|
||||
if (! $isCreate && ! $isUpdate) {
|
||||
return [
|
||||
'name' => 'nullable|string|max:255',
|
||||
'ic_number' => 'nullable|string|max:255',
|
||||
'relationship' => 'nullable|string|max:255',
|
||||
'phone_number' => 'nullable|string|max:255',
|
||||
'address' => 'nullable|string',
|
||||
'is_primary' => 'nullable|boolean',
|
||||
];
|
||||
}
|
||||
|
||||
// If this is an update operation, make email and password optional
|
||||
if ($isUpdate) {
|
||||
return [
|
||||
'name' => 'required|string|max:255',
|
||||
'ic_number' => 'required|string|max:255',
|
||||
'relationship' => 'required|string|max:255',
|
||||
'phone_number' => 'required|string|max:255',
|
||||
'address' => 'required|string',
|
||||
'is_primary' => 'required|boolean',
|
||||
];
|
||||
}
|
||||
|
||||
// Default rules for create operations
|
||||
return [
|
||||
'name' => 'required|string|max:255',
|
||||
'ic_number' => 'required|string|max:255',
|
||||
'relationship' => 'required|string|max:255',
|
||||
'phone_number' => 'required|string|max:255',
|
||||
'address' => 'required|string',
|
||||
'is_primary' => 'required|boolean',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get custom messages for validator errors.
|
||||
*/
|
||||
public function messages(): array
|
||||
{
|
||||
return [
|
||||
'name.required' => 'Nama diperlukan.',
|
||||
'name.max' => 'Nama tidak boleh melebihi 255 aksara.',
|
||||
'ic_number.required' => 'Nombor Kad Pengenalan diperlukan.',
|
||||
'ic_number.max' => 'Nombor Kad Pengenalan tidak boleh melebihi 255 aksara.',
|
||||
'relationship.required' => 'Hubungan diperlukan.',
|
||||
'relationship.max' => 'Hubungan tidak boleh melebihi 255 aksara.',
|
||||
'phone_number.required' => 'Nombor telefon diperlukan.',
|
||||
'phone_number.max' => 'Nombor telefon tidak boleh melebihi 255 aksara.',
|
||||
'address.required' => 'Alamat diperlukan.',
|
||||
'address.string' => 'Alamat tidak sah.',
|
||||
'is_primary.required' => 'Status pewaris utama diperlukan.',
|
||||
'is_primary.boolean' => 'Status pewaris utama tidak sah.',
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -39,6 +39,13 @@ class UserRequest extends FormRequest
|
||||
'phone_number' => 'nullable|string|max:255',
|
||||
'image_url' => 'nullable|string|max:255',
|
||||
'status' => 'nullable|string',
|
||||
'gender' => 'nullable|string|max:255',
|
||||
'marriage_status' => 'nullable|string|max:255',
|
||||
'member_number' => 'required|integer',
|
||||
'member_type' => 'required|string|max:255',
|
||||
'join_date' => 'nullable|date',
|
||||
'birth_date' => 'nullable|date',
|
||||
'birth_place' => 'nullable|string|max:255',
|
||||
];
|
||||
}
|
||||
|
||||
@@ -58,10 +65,17 @@ class UserRequest extends FormRequest
|
||||
// ],
|
||||
'password' => 'nullable|string|min:8',
|
||||
'ic_number' => 'required|string|max:255',
|
||||
'position' => 'required|string|max:255',
|
||||
'position' => 'nullable|string|max:255',
|
||||
'phone_number' => 'nullable|string|max:255',
|
||||
'image_url' => 'nullable|string|max:255',
|
||||
'status' => 'nullable|string',
|
||||
'gender' => 'nullable|string|max:255',
|
||||
'marriage_status' => 'nullable|string|max:255',
|
||||
'member_number' => 'required|integer',
|
||||
'member_type' => 'required|string|max:255',
|
||||
'join_date' => 'nullable|date',
|
||||
'birth_date' => 'nullable|date',
|
||||
'birth_place' => 'nullable|string|max:255',
|
||||
];
|
||||
}
|
||||
|
||||
@@ -81,6 +95,13 @@ class UserRequest extends FormRequest
|
||||
'phone_number' => 'nullable|string|max:255',
|
||||
'image_url' => 'nullable|string|max:255',
|
||||
'status' => 'required|string',
|
||||
'gender' => 'required|string|max:255',
|
||||
'marriage_status' => 'required|string|max:255',
|
||||
'member_number' => 'required|integer',
|
||||
'member_type' => 'required|string|max:255',
|
||||
'join_date' => 'required|date',
|
||||
'birth_date' => 'required|date',
|
||||
'birth_place' => 'required|string|max:255',
|
||||
];
|
||||
}
|
||||
|
||||
@@ -105,6 +126,20 @@ class UserRequest extends FormRequest
|
||||
'image_url.max' => 'URL imej tidak boleh melebihi 255 aksara.',
|
||||
'status.required' => 'Status diperlukan.',
|
||||
'status.string' => 'Status aktif tidak sah.',
|
||||
'gender.required' => 'Jenis kelamin diperlukan.',
|
||||
'gender.max' => 'Jenis kelamin tidak boleh melebihi 255 aksara.',
|
||||
'marriage_status.required' => 'Status perkahwinan diperlukan.',
|
||||
'marriage_status.max' => 'Status perkahwinan tidak boleh melebihi 255 aksara.',
|
||||
'member_number.required' => 'Nombor anggota diperlukan.',
|
||||
'member_number.integer' => 'Nombor anggota tidak sah.',
|
||||
'member_type.required' => 'Jenis anggota diperlukan.',
|
||||
'member_type.max' => 'Jenis anggota tidak boleh melebihi 255 aksara.',
|
||||
'join_date.required' => 'Tarikh join diperlukan.',
|
||||
'join_date.date' => 'Tarikh join tidak sah.',
|
||||
'birth_date.required' => 'Tarikh lahir diperlukan.',
|
||||
'birth_date.date' => 'Tarikh lahir tidak sah.',
|
||||
'birth_place.required' => 'Tempat lahir diperlukan.',
|
||||
'birth_place.max' => 'Tempat lahir tidak boleh melebihi 255 aksara.',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user