52 lines
1.5 KiB
PHP
52 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace Modules\Investment\Http\Controllers;
|
|
|
|
use App\Http\Controllers\BaseCrudController;
|
|
use Illuminate\Http\JsonResponse;
|
|
use Modules\Investment\Entities\InvestmentLimitProfile;
|
|
use Modules\Investment\Http\Requests\InvestmentLimitProfileRequest;
|
|
use Modules\Investment\Repositories\Contracts\InvestmentLimitProfileRepositoryInterface;
|
|
use Modules\Investment\Transformers\InvestmentLimitProfileResource;
|
|
|
|
class InvestmentLimitProfileController extends BaseCrudController
|
|
{
|
|
protected $modelClass = InvestmentLimitProfile::class;
|
|
|
|
protected $resourceClass = InvestmentLimitProfileResource::class;
|
|
|
|
protected $requestClass = InvestmentLimitProfileRequest::class;
|
|
|
|
protected $resourceName = 'profil had pelaburan';
|
|
|
|
protected $resourceNamePlural = 'profil had pelaburan';
|
|
|
|
public function __construct(
|
|
InvestmentLimitProfileRepositoryInterface $repository,
|
|
) {
|
|
parent::__construct($repository);
|
|
}
|
|
|
|
protected function loadShowRelations($item)
|
|
{
|
|
return $item->load(['profileLimits.investmentType:id,code,name']);
|
|
}
|
|
|
|
protected function getItemName($item): string
|
|
{
|
|
return $item->name ?? $item->id;
|
|
}
|
|
|
|
protected function checkDependencies($item): ?JsonResponse
|
|
{
|
|
if ($item->userAssignments()->whereNull('expiry_date')->exists()) {
|
|
return response()->json([
|
|
'success' => false,
|
|
'message' => 'Profil had tidak boleh dipadam kerana masih ditugaskan kepada ahli.',
|
|
], 422);
|
|
}
|
|
|
|
return null;
|
|
}
|
|
}
|