DONE: layout letter with letterhead and footer, notification for newly...
This commit is contained in:
+61
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('users', function (Blueprint $table) {
|
||||
// gender
|
||||
DB::statement("
|
||||
DO $$ BEGIN
|
||||
CREATE TYPE user_gender_enum AS ENUM (
|
||||
'Lelaki',
|
||||
'Perempuan'
|
||||
);
|
||||
EXCEPTION
|
||||
WHEN duplicate_object THEN null;
|
||||
END $$;
|
||||
");
|
||||
DB::statement("
|
||||
ALTER TABLE users
|
||||
ADD COLUMN IF NOT EXISTS gender user_gender_enum
|
||||
DEFAULT NULL
|
||||
");
|
||||
// marriage status
|
||||
$table->string('marriage_status')->nullable() ->comment('Belum Berkahwin, Berkahwin, Bercerai, Balu, Duda');
|
||||
$table->integer('member_number')->nullable();
|
||||
$table->string('member_type')->nullable() ->comment('Anggota, Pesara');
|
||||
// join date
|
||||
$table->date('join_date')->nullable();
|
||||
// birth date
|
||||
$table->date('birth_date')->nullable();
|
||||
// birth place
|
||||
$table->string('birth_place')->nullable();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('users', function (Blueprint $table) {
|
||||
$table->dropColumn('gender');
|
||||
$table->dropColumn('marriage_status');
|
||||
$table->dropColumn('member_number');
|
||||
$table->dropColumn('member_type');
|
||||
$table->dropColumn('join_date');
|
||||
$table->dropColumn('birth_date');
|
||||
$table->dropColumn('birth_place');
|
||||
});
|
||||
|
||||
DB::statement("DROP TYPE IF EXISTS user_gender_enum");
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('addresses', function (Blueprint $table) {
|
||||
$table->uuid('id')->primary();
|
||||
$table->foreignUuid('user_id')->constrained('users')->onDelete('cascade');
|
||||
$table->string('address_type')->comment('home, office, billing')->nullable();
|
||||
$table->string('address_line_1')->nullable();
|
||||
$table->string('address_line_2')->nullable();
|
||||
$table->string('city')->nullable();
|
||||
$table->string('state')->nullable();
|
||||
$table->string('postcode')->nullable();
|
||||
$table->string('country')->nullable();
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('addresses');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('employments', function (Blueprint $table) {
|
||||
$table->uuid('id')->primary();
|
||||
$table->foreignUuid('user_id')->constrained('users')->onDelete('cascade');
|
||||
$table->string('company_name');
|
||||
$table->string('job_title');
|
||||
$table->string('employment_type')->comment('Permanent, Contract, Internship, Freelance');
|
||||
$table->decimal('salary', 10, 2);
|
||||
$table->date('start_date');
|
||||
$table->date('end_date')->nullable();
|
||||
$table->boolean('is_current')->default(true);
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('employments');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('banks', function (Blueprint $table) {
|
||||
$table->uuid('id')->primary();
|
||||
$table->string('name');
|
||||
$table->string('code');
|
||||
$table->string('swift_code')->nullable();
|
||||
$table->boolean('is_active')->default(true);
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('banks');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('bank_details', function (Blueprint $table) {
|
||||
$table->uuid('id')->primary();
|
||||
$table->foreignUuid('user_id')->constrained('users')->onDelete('cascade');
|
||||
$table->foreignUuid('bank_id')->constrained('banks')->onDelete('cascade');
|
||||
$table->string('account_number');
|
||||
$table->string('account_name');
|
||||
$table->string('account_type')->comment('Saving, Current');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('bank_details');
|
||||
}
|
||||
};
|
||||
@@ -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.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('heirs', function (Blueprint $table) {
|
||||
$table->uuid('id')->primary();
|
||||
$table->foreignUuid('user_id')->constrained('users')->onDelete('cascade');
|
||||
$table->string('name');
|
||||
$table->string('ic_number');
|
||||
$table->string('relationship')->comment('Isteri, Anak, Orang Tua, Saudara, Lain-lain');
|
||||
$table->string('phone_number');
|
||||
$table->text('address')->nullable();
|
||||
$table->boolean('is_primary')->default(false)->comment('Primary heir');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('heirs');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\User\Entities;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Concerns\HasUuids;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Modules\Auth\Entities\User;
|
||||
|
||||
class Address extends Model
|
||||
{
|
||||
/** @use HasFactory<\Modules\User\Database\Factories\AddressFactory> */
|
||||
use HasUuids;
|
||||
|
||||
protected $table = 'addresses';
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var list<string>
|
||||
*/
|
||||
protected $fillable = [
|
||||
'user_id',
|
||||
'address_type',
|
||||
'address_line_1',
|
||||
'address_line_2',
|
||||
'city',
|
||||
'state',
|
||||
'postcode',
|
||||
'country',
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes that should be hidden for serialization.
|
||||
*
|
||||
* @var list<string>
|
||||
*/
|
||||
protected $hidden = [
|
||||
];
|
||||
|
||||
/**
|
||||
* Get the attributes that should be cast.
|
||||
*
|
||||
* @return array<string, string>
|
||||
*/
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'address_type' => 'string',
|
||||
'address_line_1' => 'string',
|
||||
'address_line_2' => 'string',
|
||||
'city' => 'string',
|
||||
'state' => 'string',
|
||||
'postcode' => 'string',
|
||||
'country' => 'string',
|
||||
];
|
||||
}
|
||||
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\User\Entities;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Concerns\HasUuids;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Modules\User\Entities\BankDetail;
|
||||
|
||||
class Bank extends Model
|
||||
{
|
||||
/** @use HasFactory<\Modules\User\Database\Factories\BankFactory> */
|
||||
use HasUuids;
|
||||
|
||||
protected $table = 'banks';
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var list<string>
|
||||
*/
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'code',
|
||||
'swift_code',
|
||||
'is_active',
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes that should be hidden for serialization.
|
||||
*
|
||||
* @var list<string>
|
||||
*/
|
||||
protected $hidden = [
|
||||
];
|
||||
|
||||
/**
|
||||
* Get the attributes that should be cast.
|
||||
*
|
||||
* @return array<string, string>
|
||||
*/
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'name' => 'string',
|
||||
'code' => 'string',
|
||||
'swift_code' => 'string',
|
||||
'is_active' => 'boolean',
|
||||
];
|
||||
}
|
||||
|
||||
public function bankDetails()
|
||||
{
|
||||
return $this->hasMany(BankDetail::class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\User\Entities;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Concerns\HasUuids;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Modules\User\Entities\Bank;
|
||||
use Modules\Auth\Entities\User;
|
||||
|
||||
class BankDetail extends Model
|
||||
{
|
||||
/** @use HasFactory<\Modules\User\Database\Factories\BankDetailFactory> */
|
||||
use HasUuids;
|
||||
|
||||
protected $table = 'bank_details';
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var list<string>
|
||||
*/
|
||||
protected $fillable = [
|
||||
'user_id',
|
||||
'bank_id',
|
||||
'account_name',
|
||||
'account_number',
|
||||
'account_type',
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes that should be hidden for serialization.
|
||||
*
|
||||
* @var list<string>
|
||||
*/
|
||||
protected $hidden = [
|
||||
];
|
||||
|
||||
/**
|
||||
* Get the attributes that should be cast.
|
||||
*
|
||||
* @return array<string, string>
|
||||
*/
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'user_id' => 'string',
|
||||
'bank_id' => 'string',
|
||||
'account_name' => 'string',
|
||||
'account_number' => 'string',
|
||||
'account_type' => 'string',
|
||||
];
|
||||
}
|
||||
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
public function bank()
|
||||
{
|
||||
return $this->belongsTo(Bank::class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\User\Entities;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Concerns\HasUuids;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Modules\Auth\Entities\User;
|
||||
|
||||
class Employment extends Model
|
||||
{
|
||||
/** @use HasFactory<\Modules\User\Database\Factories\EmploymentFactory> */
|
||||
use HasUuids;
|
||||
|
||||
protected $table = 'employments';
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var list<string>
|
||||
*/
|
||||
protected $fillable = [
|
||||
'user_id',
|
||||
'company_name',
|
||||
'job_title',
|
||||
'employment_type',
|
||||
'salary',
|
||||
'start_date',
|
||||
'end_date',
|
||||
'is_current',
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes that should be hidden for serialization.
|
||||
*
|
||||
* @var list<string>
|
||||
*/
|
||||
protected $hidden = [
|
||||
];
|
||||
|
||||
/**
|
||||
* Get the attributes that should be cast.
|
||||
*
|
||||
* @return array<string, string>
|
||||
*/
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'company_name' => 'string',
|
||||
'job_title' => 'string',
|
||||
'employment_type' => 'string',
|
||||
'salary' => 'decimal:2',
|
||||
'start_date' => 'date',
|
||||
'end_date' => 'date',
|
||||
'is_current' => 'boolean',
|
||||
];
|
||||
}
|
||||
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\User\Entities;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Concerns\HasUuids;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Modules\Auth\Entities\User;
|
||||
|
||||
class Heir extends Model
|
||||
{
|
||||
/** @use HasFactory<\Modules\User\Database\Factories\HeirFactory> */
|
||||
use HasUuids;
|
||||
|
||||
protected $table = 'heirs';
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var list<string>
|
||||
*/
|
||||
protected $fillable = [
|
||||
'user_id',
|
||||
'name',
|
||||
'ic_number',
|
||||
'relationship',
|
||||
'phone_number',
|
||||
'address',
|
||||
'is_primary',
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes that should be hidden for serialization.
|
||||
*
|
||||
* @var list<string>
|
||||
*/
|
||||
protected $hidden = [
|
||||
];
|
||||
|
||||
/**
|
||||
* Get the attributes that should be cast.
|
||||
*
|
||||
* @return array<string, string>
|
||||
*/
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'name' => 'string',
|
||||
'ic_number' => 'string',
|
||||
'relationship' => 'string',
|
||||
'phone_number' => 'string',
|
||||
'address' => 'string',
|
||||
'is_primary' => 'boolean',
|
||||
];
|
||||
}
|
||||
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
}
|
||||
@@ -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.',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,8 +42,6 @@ class UserActivationNotification extends Notification
|
||||
'message' => $this->getNotificationMessage(),
|
||||
'user_name' => $this->newUser->name ?? 'Unknown',
|
||||
'user_email' => $this->newUser->email ?? 'Unknown',
|
||||
'user_army_number' => $this->newUser->army_number ?? 'Unknown',
|
||||
'user_unit_name' => $this->newUser->unit->name ?? 'Unknown',
|
||||
'user_status' => $this->newUser->status ?? 'pending',
|
||||
];
|
||||
}
|
||||
@@ -55,10 +53,8 @@ class UserActivationNotification extends Notification
|
||||
{
|
||||
$userName = $this->newUser->name ?? 'Unknown';
|
||||
$userEmail = $this->newUser->email ?? 'Unknown';
|
||||
$userArmyNumber = $this->newUser->army_number ?? 'Unknown';
|
||||
$unitName = $this->newUser->unit->name ?? 'Unknown';
|
||||
|
||||
return "Pengguna baru memerlukan pengaktifan. Nama: {$userName}, Email: {$userEmail}, No. Tentera: {$userArmyNumber}, Unit: {$unitName}";
|
||||
return "Pengguna baru memerlukan pengaktifan. Nama: {$userName}, Email: {$userEmail}";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\User\Policies;
|
||||
|
||||
use Illuminate\Auth\Access\HandlesAuthorization;
|
||||
use Modules\User\Entities\Address;
|
||||
|
||||
class AddressPolicy
|
||||
{
|
||||
use HandlesAuthorization;
|
||||
|
||||
public function viewAny($user): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function view($user, ?Address $address = null): bool
|
||||
{
|
||||
return $address === null || $address->user_id === $user->id;
|
||||
}
|
||||
|
||||
public function create($user): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function update($user, ?Address $address = null): bool
|
||||
{
|
||||
return $address === null || $address->user_id === $user->id;
|
||||
}
|
||||
|
||||
public function deleteAny($user): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function delete($user, ?Address $address = null): bool
|
||||
{
|
||||
return $address === null || $address->user_id === $user->id;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\User\Policies;
|
||||
|
||||
use Illuminate\Auth\Access\HandlesAuthorization;
|
||||
use Modules\User\Entities\BankDetail;
|
||||
|
||||
class BankDetailPolicy
|
||||
{
|
||||
use HandlesAuthorization;
|
||||
|
||||
public function viewAny($user): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function view($user, ?BankDetail $bankDetail = null): bool
|
||||
{
|
||||
return $bankDetail === null || $bankDetail->user_id === $user->id;
|
||||
}
|
||||
|
||||
public function create($user): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function update($user, ?BankDetail $bankDetail = null): bool
|
||||
{
|
||||
return $bankDetail === null || $bankDetail->user_id === $user->id;
|
||||
}
|
||||
|
||||
public function deleteAny($user): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function delete($user, ?BankDetail $bankDetail = null): bool
|
||||
{
|
||||
return $bankDetail === null || $bankDetail->user_id === $user->id;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\User\Policies;
|
||||
|
||||
use Illuminate\Auth\Access\HandlesAuthorization;
|
||||
use Modules\User\Entities\Bank;
|
||||
|
||||
class BankPolicy
|
||||
{
|
||||
use HandlesAuthorization;
|
||||
|
||||
public function viewAny($user): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function view($user, ?Bank $bank = null): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function create($user): bool
|
||||
{
|
||||
return $user->hasPermissionTo('tambah bank');
|
||||
}
|
||||
|
||||
public function update($user, ?Bank $bank = null): bool
|
||||
{
|
||||
return $user->hasPermissionTo('kemaskini bank');
|
||||
}
|
||||
|
||||
public function deleteAny($user): bool
|
||||
{
|
||||
return $user->hasPermissionTo('hapus bank');
|
||||
}
|
||||
|
||||
public function delete($user, ?Bank $bank = null): bool
|
||||
{
|
||||
return $user->hasPermissionTo('hapus bank');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\User\Policies;
|
||||
|
||||
use Illuminate\Auth\Access\HandlesAuthorization;
|
||||
use Modules\User\Entities\Employment;
|
||||
|
||||
class EmploymentPolicy
|
||||
{
|
||||
use HandlesAuthorization;
|
||||
|
||||
public function viewAny($user): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function view($user, ?Employment $employement = null): bool
|
||||
{
|
||||
return $employement === null || $employement->user_id === $user->id;
|
||||
}
|
||||
|
||||
public function create($user): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function update($user, ?Employment $employement = null): bool
|
||||
{
|
||||
return $employement === null || $employement->user_id === $user->id;
|
||||
}
|
||||
|
||||
public function deleteAny($user): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function delete($user, ?Employment $employement = null): bool
|
||||
{
|
||||
return $employement === null || $employement->user_id === $user->id;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\User\Policies;
|
||||
|
||||
use Illuminate\Auth\Access\HandlesAuthorization;
|
||||
use Modules\User\Entities\Heir;
|
||||
|
||||
class HeirPolicy
|
||||
{
|
||||
use HandlesAuthorization;
|
||||
|
||||
public function viewAny($user): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function view($user, ?Heir $heir = null): bool
|
||||
{
|
||||
return $heir === null || $heir->user_id === $user->id;
|
||||
}
|
||||
|
||||
public function create($user): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function update($user, ?Heir $heir = null): bool
|
||||
{
|
||||
return $heir === null || $heir->user_id === $user->id;
|
||||
}
|
||||
|
||||
public function deleteAny($user): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function delete($user, ?Heir $heir = null): bool
|
||||
{
|
||||
return $heir === null || $heir->user_id === $user->id;
|
||||
}
|
||||
}
|
||||
@@ -30,7 +30,7 @@ class UserPolicy
|
||||
*/
|
||||
public function create($user): bool
|
||||
{
|
||||
return $user->hasPermissionTo('tambah pengguna');
|
||||
return $user->hasPermissionTo('daftar pengguna baru');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -46,7 +46,7 @@ class UserPolicy
|
||||
*/
|
||||
public function deleteAny($user): bool
|
||||
{
|
||||
return $user->hasPermissionTo('hapus pengguna');
|
||||
return $user->hasPermissionTo('padam akaun pengguna');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -54,6 +54,14 @@ class UserPolicy
|
||||
*/
|
||||
public function delete($user, ?User $userModel = null): bool
|
||||
{
|
||||
return $user->hasPermissionTo('hapus pengguna');
|
||||
return $user->hasPermissionTo('padam akaun pengguna');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can restore a soft-deleted model.
|
||||
*/
|
||||
public function restore($user, ?User $userModel = null): bool
|
||||
{
|
||||
return $user->hasPermissionTo('padam akaun pengguna');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,16 @@ use Illuminate\Support\Facades\Gate;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use Modules\Auth\Entities\User;
|
||||
use Modules\User\Policies\UserPolicy;
|
||||
use Modules\User\Entities\Address;
|
||||
use Modules\User\Policies\AddressPolicy;
|
||||
use Modules\User\Entities\Employment;
|
||||
use Modules\User\Policies\EmploymentPolicy;
|
||||
use Modules\User\Entities\Bank;
|
||||
use Modules\User\Policies\BankPolicy;
|
||||
use Modules\User\Entities\BankDetail;
|
||||
use Modules\User\Policies\BankDetailPolicy;
|
||||
use Modules\User\Entities\Heir;
|
||||
use Modules\User\Policies\HeirPolicy;
|
||||
use Nwidart\Modules\Traits\PathNamespace;
|
||||
use RecursiveDirectoryIterator;
|
||||
use RecursiveIteratorIterator;
|
||||
@@ -41,11 +51,36 @@ class UserServiceProvider extends ServiceProvider
|
||||
$this->app->register(EventServiceProvider::class);
|
||||
$this->app->register(RouteServiceProvider::class);
|
||||
|
||||
// Register repository binding
|
||||
// Register repository bindings
|
||||
$this->app->bind(
|
||||
\Modules\User\Repositories\Contracts\UserRepositoryInterface::class,
|
||||
\Modules\User\Repositories\UserRepository::class
|
||||
);
|
||||
|
||||
$this->app->bind(
|
||||
\Modules\User\Repositories\Contracts\AddressRepositoryInterface::class,
|
||||
\Modules\User\Repositories\AddressRepository::class
|
||||
);
|
||||
|
||||
$this->app->bind(
|
||||
\Modules\User\Repositories\Contracts\EmploymentRepositoryInterface::class,
|
||||
\Modules\User\Repositories\EmploymentRepository::class
|
||||
);
|
||||
|
||||
$this->app->bind(
|
||||
\Modules\User\Repositories\Contracts\BankRepositoryInterface::class,
|
||||
\Modules\User\Repositories\BankRepository::class
|
||||
);
|
||||
|
||||
$this->app->bind(
|
||||
\Modules\User\Repositories\Contracts\BankDetailRepositoryInterface::class,
|
||||
\Modules\User\Repositories\BankDetailRepository::class
|
||||
);
|
||||
|
||||
$this->app->bind(
|
||||
\Modules\User\Repositories\Contracts\HeirRepositoryInterface::class,
|
||||
\Modules\User\Repositories\HeirRepository::class
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -54,6 +89,11 @@ class UserServiceProvider extends ServiceProvider
|
||||
protected function registerPolicies(): void
|
||||
{
|
||||
Gate::policy(User::class, UserPolicy::class);
|
||||
Gate::policy(Address::class, AddressPolicy::class);
|
||||
Gate::policy(Employment::class, EmploymentPolicy::class);
|
||||
Gate::policy(Bank::class, BankPolicy::class);
|
||||
Gate::policy(BankDetail::class, BankDetailPolicy::class);
|
||||
Gate::policy(Heir::class, HeirPolicy::class);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,89 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\User\Repositories;
|
||||
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Modules\User\Entities\Address;
|
||||
use Modules\User\Repositories\Contracts\AddressRepositoryInterface;
|
||||
|
||||
class AddressRepository implements AddressRepositoryInterface
|
||||
{
|
||||
protected function baseQuery()
|
||||
{
|
||||
return Address::query()
|
||||
->where('user_id', auth()->id())
|
||||
->orderBy('address_type');
|
||||
}
|
||||
|
||||
public function getAllPaginated(int $perPage = 10, string $search = '')
|
||||
{
|
||||
$query = $this->baseQuery();
|
||||
|
||||
return $query->paginate($perPage);
|
||||
}
|
||||
|
||||
public function getAllWithRelationsPaginated(
|
||||
int $perPage = 10,
|
||||
string $search = '',
|
||||
string $sortBy = 'address_type',
|
||||
string $sortOrder = 'asc'
|
||||
) {
|
||||
$allowedSortColumns = [
|
||||
'id',
|
||||
'address_type',
|
||||
'address_line_1',
|
||||
'city',
|
||||
'state',
|
||||
'postcode',
|
||||
'country',
|
||||
'created_at',
|
||||
];
|
||||
$sortBy = in_array($sortBy, $allowedSortColumns, true) ? $sortBy : 'address_type';
|
||||
$sortOrder = strtolower($sortOrder) === 'desc' ? 'desc' : 'asc';
|
||||
|
||||
$query = Address::query()
|
||||
->where('user_id', auth()->id())
|
||||
->with(['user:id,name,email'])
|
||||
->orderBy($sortBy, $sortOrder);
|
||||
|
||||
return $query->paginate($perPage);
|
||||
}
|
||||
|
||||
public function getAllWithRelations(string $search = ''): Collection
|
||||
{
|
||||
$query = Address::query()
|
||||
->where('user_id', auth()->id())
|
||||
->with(['user:id,name,email'])
|
||||
->orderBy('address_type');
|
||||
|
||||
return $query->get();
|
||||
}
|
||||
|
||||
public function create(array $data): Address
|
||||
{
|
||||
return Address::create($data);
|
||||
}
|
||||
|
||||
public function findById(string $id): ?Address
|
||||
{
|
||||
return Address::query()
|
||||
->where('user_id', auth()->id())
|
||||
->with(['user:id,name,email'])
|
||||
->find($id);
|
||||
}
|
||||
|
||||
public function delete(string $id): bool
|
||||
{
|
||||
$address = $this->findById($id);
|
||||
if ($address) {
|
||||
return $address->delete();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function all(string $search = ''): Collection
|
||||
{
|
||||
return $this->baseQuery()->get();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\User\Repositories;
|
||||
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Modules\User\Entities\BankDetail;
|
||||
use Modules\User\Repositories\Contracts\BankDetailRepositoryInterface;
|
||||
|
||||
class BankDetailRepository implements BankDetailRepositoryInterface
|
||||
{
|
||||
protected function baseQuery()
|
||||
{
|
||||
return BankDetail::query()->where('user_id', auth()->id());
|
||||
}
|
||||
|
||||
public function getAllPaginated(int $perPage = 10, string $search = '')
|
||||
{
|
||||
$query = $this->baseQuery();
|
||||
|
||||
return $query->paginate($perPage);
|
||||
}
|
||||
|
||||
public function getAllWithRelations(string $search = ''): Collection
|
||||
{
|
||||
$query = BankDetail::query()
|
||||
->where('user_id', auth()->id())
|
||||
->with(['user:id,name,email', 'bank:id,name'])
|
||||
->orderBy('account_number');
|
||||
|
||||
return $query->get();
|
||||
}
|
||||
|
||||
public function create(array $data): BankDetail
|
||||
{
|
||||
return BankDetail::create($data);
|
||||
}
|
||||
|
||||
public function findById(string $id): ?BankDetail
|
||||
{
|
||||
return BankDetail::query()
|
||||
->where('user_id', auth()->id())
|
||||
->find($id);
|
||||
}
|
||||
|
||||
public function delete(string $id): bool
|
||||
{
|
||||
$bankDetail = $this->findById($id);
|
||||
if ($bankDetail) {
|
||||
return $bankDetail->delete();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function all(string $search = ''): Collection
|
||||
{
|
||||
return $this->baseQuery()->get();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\User\Repositories;
|
||||
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Modules\User\Entities\Bank;
|
||||
use Modules\User\Repositories\Contracts\BankRepositoryInterface;
|
||||
|
||||
class BankRepository implements BankRepositoryInterface
|
||||
{
|
||||
protected function baseQuery()
|
||||
{
|
||||
return Bank::query()->orderBy('name');
|
||||
}
|
||||
|
||||
public function getAllPaginated(int $perPage = 10, string $search = '')
|
||||
{
|
||||
$query = $this->baseQuery();
|
||||
|
||||
return $query->paginate($perPage);
|
||||
}
|
||||
|
||||
public function getAllWithRelationsPaginated(
|
||||
int $perPage = 10,
|
||||
string $search = '',
|
||||
string $sortBy = 'name',
|
||||
string $sortOrder = 'asc'
|
||||
) {
|
||||
$allowedSortColumns = [
|
||||
'name',
|
||||
'code',
|
||||
'swift_code',
|
||||
'is_active',
|
||||
'created_at',
|
||||
];
|
||||
$sortBy = in_array($sortBy, $allowedSortColumns, true) ? $sortBy : 'name';
|
||||
$sortOrder = strtolower($sortOrder) === 'desc' ? 'desc' : 'asc';
|
||||
|
||||
$query = Bank::query()->orderBy($sortBy, $sortOrder);
|
||||
|
||||
return $query->paginate($perPage);
|
||||
}
|
||||
|
||||
public function getAllWithRelations(string $search = ''): Collection
|
||||
{
|
||||
$query = Bank::query()->orderBy('name');
|
||||
|
||||
return $query->get();
|
||||
}
|
||||
|
||||
public function create(array $data): Bank
|
||||
{
|
||||
return Bank::create($data);
|
||||
}
|
||||
|
||||
public function findById(string $id): ?Bank
|
||||
{
|
||||
return Bank::query()
|
||||
->find($id);
|
||||
}
|
||||
|
||||
// public function delete(string $id): bool
|
||||
// {
|
||||
// $bank = $this->findById($id);
|
||||
// if ($bank) {
|
||||
// return $bank->delete();
|
||||
// }
|
||||
|
||||
// return false;
|
||||
// }
|
||||
|
||||
public function all(string $search = ''): Collection
|
||||
{
|
||||
return $this->baseQuery()->get();
|
||||
}
|
||||
|
||||
public function active(): Collection
|
||||
{
|
||||
return Bank::query()->where('is_active', true)->get();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\User\Repositories\Contracts;
|
||||
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Modules\User\Entities\Address;
|
||||
|
||||
interface AddressRepositoryInterface
|
||||
{
|
||||
public function getAllPaginated(int $perPage = 10, string $search = '');
|
||||
|
||||
public function getAllWithRelationsPaginated(
|
||||
int $perPage = 10,
|
||||
string $search = '',
|
||||
string $sortBy = 'address_type',
|
||||
string $sortOrder = 'asc'
|
||||
);
|
||||
|
||||
public function getAllWithRelations(string $search = ''): Collection;
|
||||
|
||||
public function create(array $data): Address;
|
||||
|
||||
public function findById(string $id): ?Address;
|
||||
|
||||
public function delete(string $id): bool;
|
||||
|
||||
public function all(string $search = ''): Collection;
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\User\Repositories\Contracts;
|
||||
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Modules\User\Entities\BankDetail;
|
||||
|
||||
interface BankDetailRepositoryInterface
|
||||
{
|
||||
public function getAllPaginated(int $perPage = 10, string $search = '');
|
||||
|
||||
public function getAllWithRelations(string $search = ''): Collection;
|
||||
|
||||
public function create(array $data): BankDetail;
|
||||
|
||||
public function findById(string $id): ?BankDetail;
|
||||
|
||||
public function delete(string $id): bool;
|
||||
|
||||
public function all(string $search = ''): Collection;
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\User\Repositories\Contracts;
|
||||
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Modules\User\Entities\Bank;
|
||||
|
||||
interface BankRepositoryInterface
|
||||
{
|
||||
public function getAllPaginated(int $perPage = 10, string $search = '');
|
||||
|
||||
public function getAllWithRelationsPaginated(
|
||||
int $perPage = 10,
|
||||
string $search = '',
|
||||
string $sortBy = 'name',
|
||||
string $sortOrder = 'asc'
|
||||
);
|
||||
|
||||
public function getAllWithRelations(string $search = ''): Collection;
|
||||
|
||||
public function create(array $data): Bank;
|
||||
|
||||
public function findById(string $id): ?Bank;
|
||||
|
||||
// public function delete(string $id): bool;
|
||||
|
||||
public function all(string $search = ''): Collection;
|
||||
|
||||
public function active(): Collection;
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\User\Repositories\Contracts;
|
||||
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Modules\User\Entities\Employment;
|
||||
|
||||
interface EmploymentRepositoryInterface
|
||||
{
|
||||
public function getAllPaginated(int $perPage = 10, string $search = '');
|
||||
|
||||
public function getAllWithRelationsPaginated(
|
||||
int $perPage = 10,
|
||||
string $search = '',
|
||||
string $sortBy = 'company_name',
|
||||
string $sortOrder = 'asc'
|
||||
);
|
||||
|
||||
public function getAllWithRelations(string $search = ''): Collection;
|
||||
|
||||
public function create(array $data): Employment;
|
||||
|
||||
public function findById(string $id): ?Employment;
|
||||
|
||||
public function delete(string $id): bool;
|
||||
|
||||
public function all(string $search = ''): Collection;
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\User\Repositories\Contracts;
|
||||
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Modules\User\Entities\Heir;
|
||||
|
||||
interface HeirRepositoryInterface
|
||||
{
|
||||
public function getAllPaginated(int $perPage = 10, string $search = '');
|
||||
|
||||
// public function getAllWithRelationsPaginated(
|
||||
// int $perPage = 10,
|
||||
// string $search = '',
|
||||
// string $sortBy = 'name',
|
||||
// string $sortOrder = 'asc'
|
||||
// );
|
||||
|
||||
public function getAllWithRelations(string $search = ''): Collection;
|
||||
|
||||
public function create(array $data): Heir;
|
||||
|
||||
public function findById(string $id): ?Heir;
|
||||
|
||||
public function delete(string $id): bool;
|
||||
|
||||
public function all(string $search = ''): Collection;
|
||||
}
|
||||
@@ -43,6 +43,27 @@ interface UserRepositoryInterface
|
||||
*/
|
||||
public function delete(string $id): bool;
|
||||
|
||||
/**
|
||||
* Get soft-deleted Users with their relationships and pagination
|
||||
*/
|
||||
public function getDeletedWithRelationsPaginated(
|
||||
int $perPage = 10,
|
||||
string $search = '',
|
||||
string $status = '',
|
||||
string $sortBy = 'deleted_at',
|
||||
string $sortOrder = 'desc'
|
||||
);
|
||||
|
||||
/**
|
||||
* Find soft-deleted User by ID
|
||||
*/
|
||||
public function findTrashedById(string $id): ?User;
|
||||
|
||||
/**
|
||||
* Restore a soft-deleted User
|
||||
*/
|
||||
public function restore(string $id): bool;
|
||||
|
||||
/**
|
||||
* Get all Users
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\User\Repositories;
|
||||
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Modules\User\Entities\Employment;
|
||||
use Modules\User\Repositories\Contracts\EmploymentRepositoryInterface;
|
||||
|
||||
class EmploymentRepository implements EmploymentRepositoryInterface
|
||||
{
|
||||
protected function baseQuery()
|
||||
{
|
||||
return Employment::query()
|
||||
->where('user_id', auth()->id())
|
||||
->orderBy('company_name');
|
||||
}
|
||||
|
||||
public function getAllPaginated(int $perPage = 10, string $search = '')
|
||||
{
|
||||
$query = $this->baseQuery();
|
||||
|
||||
return $query->paginate($perPage);
|
||||
}
|
||||
|
||||
public function getAllWithRelationsPaginated(
|
||||
int $perPage = 10,
|
||||
string $search = '',
|
||||
string $sortBy = 'company_name',
|
||||
string $sortOrder = 'asc'
|
||||
) {
|
||||
$allowedSortColumns = [
|
||||
'id',
|
||||
'company_name',
|
||||
'job_title',
|
||||
'employment_type',
|
||||
'salary',
|
||||
'start_date',
|
||||
'end_date',
|
||||
'is_current',
|
||||
'created_at',
|
||||
];
|
||||
$sortBy = in_array($sortBy, $allowedSortColumns, true) ? $sortBy : 'company_name';
|
||||
$sortOrder = strtolower($sortOrder) === 'desc' ? 'desc' : 'asc';
|
||||
|
||||
$query = Employment::query()
|
||||
->where('user_id', auth()->id())
|
||||
->with(['user:id,name,email'])
|
||||
->orderBy($sortBy, $sortOrder);
|
||||
|
||||
return $query->paginate($perPage);
|
||||
}
|
||||
|
||||
public function getAllWithRelations(string $search = ''): Collection
|
||||
{
|
||||
$query = Employment::query()
|
||||
->where('user_id', auth()->id())
|
||||
->with(['user:id,name,email'])
|
||||
->orderBy('company_name');
|
||||
|
||||
return $query->get();
|
||||
}
|
||||
|
||||
public function create(array $data): Employment
|
||||
{
|
||||
return Employment::create($data);
|
||||
}
|
||||
|
||||
public function findById(string $id): ?Employment
|
||||
{
|
||||
return Employment::query()
|
||||
->where('user_id', auth()->id())
|
||||
->with(['user:id,name,email'])
|
||||
->find($id);
|
||||
}
|
||||
|
||||
public function delete(string $id): bool
|
||||
{
|
||||
$employement = $this->findById($id);
|
||||
if ($employement) {
|
||||
return $employement->delete();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function all(string $search = ''): Collection
|
||||
{
|
||||
return $this->baseQuery()->get();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\User\Repositories;
|
||||
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Modules\User\Entities\Heir;
|
||||
use Modules\User\Repositories\Contracts\HeirRepositoryInterface;
|
||||
|
||||
class HeirRepository implements HeirRepositoryInterface
|
||||
{
|
||||
protected function baseQuery()
|
||||
{
|
||||
return Heir::query()
|
||||
->where('user_id', auth()->id())
|
||||
->orderBy('name');
|
||||
}
|
||||
|
||||
public function getAllPaginated(int $perPage = 10, string $search = '')
|
||||
{
|
||||
$query = $this->baseQuery();
|
||||
|
||||
return $query->paginate($perPage);
|
||||
}
|
||||
|
||||
// public function getAllWithRelationsPaginated(
|
||||
// int $perPage = 10,
|
||||
// string $search = '',
|
||||
// string $sortBy = 'name',
|
||||
// string $sortOrder = 'asc'
|
||||
// ) {
|
||||
// $allowedSortColumns = [
|
||||
// 'id',
|
||||
// 'name',
|
||||
// 'job_title',
|
||||
// 'relationship',
|
||||
// 'phone_number',
|
||||
// 'address',
|
||||
// 'is_primary',
|
||||
// 'created_at',
|
||||
// ];
|
||||
// $sortBy = in_array($sortBy, $allowedSortColumns, true) ? $sortBy : 'company_name';
|
||||
// $sortOrder = strtolower($sortOrder) === 'desc' ? 'desc' : 'asc';
|
||||
|
||||
// $query = Employment::query()
|
||||
// ->where('user_id', auth()->id())
|
||||
// ->with(['user:id,name,email'])
|
||||
// ->orderBy($sortBy, $sortOrder);
|
||||
|
||||
// return $query->paginate($perPage);
|
||||
// }
|
||||
|
||||
public function getAllWithRelations(string $search = ''): Collection
|
||||
{
|
||||
$query = Heir::query()
|
||||
->where('user_id', auth()->id())
|
||||
->with(['user:id,name,email'])
|
||||
->orderBy('name');
|
||||
|
||||
return $query->get();
|
||||
}
|
||||
|
||||
public function create(array $data): Heir
|
||||
{
|
||||
return Heir::create($data);
|
||||
}
|
||||
|
||||
public function findById(string $id): ?Heir
|
||||
{
|
||||
return Heir::query()
|
||||
->where('user_id', auth()->id())
|
||||
->with(['user:id,name,email'])
|
||||
->find($id);
|
||||
}
|
||||
|
||||
public function delete(string $id): bool
|
||||
{
|
||||
$heir = $this->findById($id);
|
||||
if ($heir) {
|
||||
return $heir->delete();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function all(string $search = ''): Collection
|
||||
{
|
||||
return $this->baseQuery()->get();
|
||||
}
|
||||
}
|
||||
@@ -8,24 +8,32 @@ use Modules\User\Repositories\Contracts\UserRepositoryInterface;
|
||||
|
||||
class UserRepository implements UserRepositoryInterface
|
||||
{
|
||||
private function applySearch($query, string $search): void
|
||||
{
|
||||
if (empty($search)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$query->where(function ($q) use ($search) {
|
||||
$q->where('name', 'ILIKE', "%{$search}%")
|
||||
->orWhere('ic_number', 'ILIKE', "%{$search}%")
|
||||
->orWhere('email', 'ILIKE', "%{$search}%")
|
||||
->orWhere('phone_number', 'ILIKE', "%{$search}%")
|
||||
->orWhere('member_number', 'ILIKE', "%{$search}%")
|
||||
->orWhereHas('roles', function ($roleQuery) use ($search) {
|
||||
$roleQuery->whereRaw('LOWER(name) ILIKE ?', ['%' . strtolower($search) . '%']);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all Users with pagination and search
|
||||
*/
|
||||
public function getAllPaginated(int $perPage = 10, string $search = '')
|
||||
{
|
||||
$query = User::visibleTo(auth()->user())->excludeDevelopersUnlessDeveloper()->orderBy('name');
|
||||
$query = User::excludeDevelopersUnlessDeveloper()->orderBy('name');
|
||||
|
||||
if (! empty($search)) {
|
||||
$query->where(function ($q) use ($search) {
|
||||
$q->where('name', 'ILIKE', "%{$search}%");
|
||||
$q->orWhere('ic_number', 'ILIKE', "%{$search}%");
|
||||
$q->orWhere('email', 'ILIKE', "%{$search}%");
|
||||
$q->orWhere('phone_number', 'ILIKE', "%{$search}%");
|
||||
$q->orWhereHas('roles', function ($roleQuery) use ($search) {
|
||||
$roleQuery->whereRaw('LOWER(name) ILIKE ?', ['%' . strtolower($search) . '%']);
|
||||
});
|
||||
});
|
||||
}
|
||||
$this->applySearch($query, $search);
|
||||
|
||||
return $query->paginate($perPage);
|
||||
}
|
||||
@@ -46,38 +54,60 @@ class UserRepository implements UserRepositoryInterface
|
||||
'email',
|
||||
'position',
|
||||
'status',
|
||||
'ic_number',
|
||||
'phone_number',
|
||||
'member_number',
|
||||
'created_at',
|
||||
'deleted_at',
|
||||
];
|
||||
$sortBy = in_array($sortBy, $allowedSortColumns, true) ? $sortBy : 'name';
|
||||
$sortOrder = strtolower($sortOrder) === 'desc' ? 'desc' : 'asc';
|
||||
|
||||
$query = User::visibleTo(auth()->user())->excludeDevelopersUnlessDeveloper()
|
||||
$query = User::excludeDevelopersUnlessDeveloper()
|
||||
->with([
|
||||
'roles:id,name,guard_name'
|
||||
])
|
||||
->orderBy($sortBy, $sortOrder);
|
||||
|
||||
if (! empty($search)) {
|
||||
$query->where(function ($q) use ($search) {
|
||||
$q->where('name', 'ILIKE', "%{$search}%")
|
||||
->orWhere('ic_number', 'ILIKE', "%{$search}%")
|
||||
->orWhere('email', 'ILIKE', "%{$search}%")
|
||||
->orWhere('phone_number', 'ILIKE', "%{$search}%")
|
||||
->orWhereHas('roles', function ($roleQuery) use ($search) {
|
||||
$roleQuery->whereRaw('LOWER(name) ILIKE ?', ['%' . strtolower($search) . '%']);
|
||||
});
|
||||
$q->orWhere('ic_number', 'ILIKE', "%{$search}%");
|
||||
$q->orWhere('email', 'ILIKE', "%{$search}%");
|
||||
$q->orWhere('phone_number', 'ILIKE', "%{$search}%");
|
||||
$q->orWhereHas('roles', function ($roleQuery) use ($search) {
|
||||
$roleQuery->whereRaw('LOWER(name) ILIKE ?', ['%' . strtolower($search) . '%']);
|
||||
});
|
||||
});
|
||||
$this->applySearch($query, $search);
|
||||
|
||||
if (! empty($status)) {
|
||||
$query->where('status', $status);
|
||||
}
|
||||
|
||||
// Add status filter
|
||||
return $query->paginate($perPage);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get soft-deleted Users with their relationships and pagination
|
||||
*/
|
||||
public function getDeletedWithRelationsPaginated(
|
||||
int $perPage = 10,
|
||||
string $search = '',
|
||||
string $status = '',
|
||||
string $sortBy = 'deleted_at',
|
||||
string $sortOrder = 'desc'
|
||||
) {
|
||||
$allowedSortColumns = [
|
||||
'id',
|
||||
'name',
|
||||
'email',
|
||||
'position',
|
||||
'status',
|
||||
'member_number',
|
||||
'created_at',
|
||||
'deleted_at',
|
||||
];
|
||||
$sortBy = in_array($sortBy, $allowedSortColumns, true) ? $sortBy : 'deleted_at';
|
||||
$sortOrder = strtolower($sortOrder) === 'desc' ? 'desc' : 'asc';
|
||||
|
||||
$query = User::onlyTrashed()
|
||||
->excludeDevelopersUnlessDeveloper()
|
||||
->with([
|
||||
'roles:id,name,guard_name',
|
||||
])
|
||||
->orderBy($sortBy, $sortOrder);
|
||||
|
||||
$this->applySearch($query, $search);
|
||||
|
||||
if (! empty($status)) {
|
||||
$query->where('status', $status);
|
||||
}
|
||||
@@ -90,19 +120,9 @@ class UserRepository implements UserRepositoryInterface
|
||||
*/
|
||||
public function getAllWithRelations(string $search = ''): Collection
|
||||
{
|
||||
$query = User::visibleTo(auth()->user())->excludeDevelopersUnlessDeveloper()->orderBy('name');
|
||||
$query = User::excludeDevelopersUnlessDeveloper()->orderBy('name');
|
||||
|
||||
if (! empty($search)) {
|
||||
$query->where(function ($q) use ($search) {
|
||||
$q->where('name', 'ILIKE', "%{$search}%")
|
||||
->orWhere('ic_number', 'ILIKE', "%{$search}%")
|
||||
->orWhere('email', 'ILIKE', "%{$search}%")
|
||||
->orWhere('phone_number', 'ILIKE', "%{$search}%")
|
||||
->orWhereHas('roles', function ($roleQuery) use ($search) {
|
||||
$roleQuery->whereRaw('LOWER(name) ILIKE ?', ['%' . strtolower($search) . '%']);
|
||||
});
|
||||
});
|
||||
}
|
||||
$this->applySearch($query, $search);
|
||||
|
||||
return $query->get();
|
||||
}
|
||||
@@ -136,24 +156,36 @@ class UserRepository implements UserRepositoryInterface
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find soft-deleted User by ID
|
||||
*/
|
||||
public function findTrashedById(string $id): ?User
|
||||
{
|
||||
return User::onlyTrashed()->with(['roles'])->find($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Restore a soft-deleted User
|
||||
*/
|
||||
public function restore(string $id): bool
|
||||
{
|
||||
$user = User::onlyTrashed()->find($id);
|
||||
|
||||
if ($user) {
|
||||
return (bool) $user->restore();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all Ranks
|
||||
*/
|
||||
public function all(string $search = ''): Collection
|
||||
{
|
||||
$query = User::visibleTo(auth()->user())->excludeDevelopersUnlessDeveloper()->orderBy('name');
|
||||
$query = User::excludeDevelopersUnlessDeveloper()->orderBy('name');
|
||||
|
||||
if (! empty($search)) {
|
||||
$query->where(function ($q) use ($search) {
|
||||
$q->where('name', 'ILIKE', "%{$search}%")
|
||||
->orWhere('ic_number', 'ILIKE', "%{$search}%")
|
||||
->orWhere('email', 'ILIKE', "%{$search}%")
|
||||
->orWhere('phone_number', 'ILIKE', "%{$search}%")
|
||||
->orWhereHas('roles', function ($roleQuery) use ($search) {
|
||||
$roleQuery->whereRaw('LOWER(name) ILIKE ?', ['%' . strtolower($search) . '%']);
|
||||
});
|
||||
});
|
||||
}
|
||||
$this->applySearch($query, $search);
|
||||
|
||||
return $query->get();
|
||||
}
|
||||
|
||||
@@ -3,10 +3,25 @@
|
||||
use Illuminate\Support\Facades\Route;
|
||||
use Modules\User\Http\Controllers\UserController;
|
||||
use App\Http\Controllers\ImpersonateController;
|
||||
use Modules\User\Http\Controllers\AddressController;
|
||||
use Modules\User\Http\Controllers\EmploymentController;
|
||||
use Modules\User\Http\Controllers\BankController;
|
||||
use Modules\User\Http\Controllers\BankDetailController;
|
||||
use Modules\User\Http\Controllers\HeirController;
|
||||
|
||||
Route::middleware(['auth:sanctum', 'single.session'])->prefix('v1')->group(function () {
|
||||
Route::get('users/deleted', [UserController::class, 'deletedIndex'])->name('users.deleted.index');
|
||||
Route::post('users/{id}/restore', [UserController::class, 'restore'])->name('users.restore');
|
||||
Route::apiResource('users', UserController::class)->names('user');
|
||||
|
||||
Route::apiResource('addresses', AddressController::class)->names('address');
|
||||
// employement
|
||||
Route::apiResource('employments', EmploymentController::class)->names('employment');
|
||||
// bank and bank detail
|
||||
Route::get('banks/active', [BankController::class, 'active'])->name('bank.active');
|
||||
Route::apiResource('banks', BankController::class)->names('bank');
|
||||
Route::apiResource('bank_details', BankDetailController::class)->names('bank_detail');
|
||||
// heir
|
||||
Route::apiResource('heirs', HeirController::class)->names('heir');
|
||||
// User role management routes
|
||||
Route::post('users/{user}/roles', [UserController::class, 'assignRoles'])->name('users.roles.assign');
|
||||
|
||||
|
||||
@@ -32,12 +32,43 @@ class UserService
|
||||
);
|
||||
}
|
||||
|
||||
public function getDeletedPaginatedList(
|
||||
int $perPage,
|
||||
string $search,
|
||||
string $status,
|
||||
string $sortBy,
|
||||
string $sortOrder
|
||||
): LengthAwarePaginator {
|
||||
return $this->repository->getDeletedWithRelationsPaginated(
|
||||
$perPage,
|
||||
$search,
|
||||
$status,
|
||||
$sortBy,
|
||||
$sortOrder
|
||||
);
|
||||
}
|
||||
|
||||
public function restoreUser(string $id): ?User
|
||||
{
|
||||
if (! $this->repository->restore($id)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $this->repository->findById($id);
|
||||
}
|
||||
|
||||
public function getUserWithRelations(string $id): ?User
|
||||
{
|
||||
$user = $this->repository->findById($id);
|
||||
|
||||
if ($user) {
|
||||
$user->load(['roles.permissions']);
|
||||
$user->load([
|
||||
'roles.permissions',
|
||||
'addresses',
|
||||
'employments',
|
||||
'bankDetails.bank',
|
||||
'heirs',
|
||||
]);
|
||||
}
|
||||
|
||||
return $user;
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\User\Transformers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class AddressResource extends JsonResource
|
||||
{
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'user_id' => $this->user_id,
|
||||
'address_type' => $this->address_type,
|
||||
'address_line_1' => $this->address_line_1,
|
||||
'address_line_2' => $this->address_line_2,
|
||||
'city' => $this->city,
|
||||
'state' => $this->state,
|
||||
'postcode' => $this->postcode,
|
||||
'country' => $this->country,
|
||||
'created_at' => $this->created_at?->toISOString(),
|
||||
'updated_at' => $this->updated_at?->toISOString(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\User\Transformers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
use Modules\User\Transformers\BankResource;
|
||||
|
||||
class BankDetailResource extends JsonResource
|
||||
{
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'user_id' => $this->user_id,
|
||||
'bank_id' => $this->bank_id,
|
||||
'account_number' => $this->account_number,
|
||||
'account_name' => $this->account_name,
|
||||
'account_type' => $this->account_type,
|
||||
'bank' => new BankResource($this->whenLoaded('bank')),
|
||||
'created_at' => $this->created_at?->toISOString(),
|
||||
'updated_at' => $this->updated_at?->toISOString(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\User\Transformers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class BankResource extends JsonResource
|
||||
{
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'name' => $this->name,
|
||||
'code' => $this->code,
|
||||
'swift_code' => $this->swift_code,
|
||||
'is_active' => $this->is_active,
|
||||
'created_at' => $this->created_at?->toISOString(),
|
||||
'updated_at' => $this->updated_at?->toISOString(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\User\Transformers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class EmploymentResource extends JsonResource
|
||||
{
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'user_id' => $this->user_id,
|
||||
'company_name' => $this->company_name,
|
||||
'job_title' => $this->job_title,
|
||||
'employment_type' => $this->employment_type,
|
||||
'salary' => $this->salary,
|
||||
'start_date' => $this->start_date,
|
||||
'end_date' => $this->end_date,
|
||||
'is_current' => $this->is_current,
|
||||
'created_at' => $this->created_at?->toISOString(),
|
||||
'updated_at' => $this->updated_at?->toISOString(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\User\Transformers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class HeirResource extends JsonResource
|
||||
{
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'user_id' => $this->user_id,
|
||||
'name' => $this->name,
|
||||
'ic_number' => $this->ic_number,
|
||||
'relationship' => $this->relationship,
|
||||
'phone_number' => $this->phone_number,
|
||||
'address' => $this->address,
|
||||
'is_primary' => $this->is_primary,
|
||||
'created_at' => $this->created_at?->toISOString(),
|
||||
'updated_at' => $this->updated_at?->toISOString(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -20,6 +20,13 @@ class UserListResource extends JsonResource
|
||||
'image_url' => $this->image_url ? Storage::disk('public')->url($this->image_url) : null,
|
||||
'status' => $this->status,
|
||||
'email_verified_at' => $this->email_verified_at,
|
||||
'gender' => $this->gender,
|
||||
'marriage_status' => $this->marriage_status,
|
||||
'member_number' => $this->member_number,
|
||||
'member_type' => $this->member_type,
|
||||
'join_date' => $this->join_date,
|
||||
'birth_date' => $this->birth_date,
|
||||
'birth_place' => $this->birth_place,
|
||||
'created_at' => $this->created_at,
|
||||
'updated_at' => $this->updated_at,
|
||||
'deleted_at' => $this->deleted_at,
|
||||
|
||||
@@ -1,54 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\User\Transformers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
class UserResource extends JsonResource
|
||||
{
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'name' => $this->name,
|
||||
'email' => $this->email,
|
||||
'ic_number' => $this->ic_number,
|
||||
'position' => $this->position,
|
||||
'phone_number' => $this->phone_number,
|
||||
'image_url' => $this->image_url ? Storage::disk('public')->url($this->image_url) : null,
|
||||
'status' => $this->status,
|
||||
'two_factor_secret' => $this->two_factor_secret,
|
||||
'two_factor_recovery_codes' => $this->two_factor_recovery_codes,
|
||||
'two_factor_confirmed_at' => $this->two_factor_confirmed_at,
|
||||
'email_verified_at' => $this->email_verified_at,
|
||||
'created_at' => $this->created_at,
|
||||
'updated_at' => $this->updated_at,
|
||||
'deleted_at' => $this->deleted_at,
|
||||
'roles' => $this->whenLoaded('roles', function () {
|
||||
return $this->roles->map(function ($role) {
|
||||
return [
|
||||
'id' => $role->id,
|
||||
'name' => $role->name,
|
||||
'guard_name' => $role->guard_name,
|
||||
'permissions' => $this->when($role->relationLoaded('permissions'), function () use ($role) {
|
||||
return $role->permissions->map(function ($permission) {
|
||||
return [
|
||||
'id' => $permission->id,
|
||||
'name' => $permission->name,
|
||||
'guard_name' => $permission->guard_name,
|
||||
'route_name' => $permission->route_name,
|
||||
'created_at' => $permission->created_at,
|
||||
'updated_at' => $permission->updated_at,
|
||||
];
|
||||
});
|
||||
}),
|
||||
'created_at' => $role->created_at,
|
||||
'updated_at' => $role->updated_at,
|
||||
];
|
||||
});
|
||||
}),
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user