mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/unity.git
synced 2026-08-19 20:34:01 +00:00
99 lines
2.5 KiB
PHP
99 lines
2.5 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Rules\User;
|
|
|
|
use Auth;
|
|
use App\Models\Entity;
|
|
use App\Models\ContractTemplate;
|
|
use App\Models\ContractTemplateObligation;
|
|
|
|
use App\Http\Helpers\Hasher;
|
|
|
|
use Illuminate\Contracts\Validation\Rule;
|
|
|
|
class UnderCheck implements Rule
|
|
{
|
|
/**
|
|
* Create a new rule instance.
|
|
*
|
|
* @return void
|
|
*/
|
|
|
|
private $type;
|
|
|
|
public function __construct($type = '')
|
|
{
|
|
$this->type = $type;
|
|
}
|
|
|
|
/**
|
|
* Determine if the validation rule passes.
|
|
*
|
|
* @param string $attribute
|
|
* @param mixed $value
|
|
* @return bool
|
|
*/
|
|
public function passes($attribute, $value)
|
|
{
|
|
$this->attribute = $attribute;
|
|
$value = is_array($value) ? $value : [$value];
|
|
|
|
if ($this->type == 'entity') {
|
|
foreach ($value as $key => $row) {
|
|
if(!empty($row)) {
|
|
$id = Hasher::decode('entities', $row);
|
|
$data = Entity::
|
|
where('id', $id)
|
|
->where('user_id', Auth::guard('user-api')->user()->id)
|
|
->count();
|
|
if (!$data) {
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
if ($this->type == 'contract_template') {
|
|
foreach ($value as $key => $row) {
|
|
if(!empty($row)) {
|
|
$id = Hasher::decode('contract_templates', $row);
|
|
$data = ContractTemplate::
|
|
where('id', $id)
|
|
->where('user_id', Auth::guard('user-api')->user()->id)
|
|
->count();
|
|
if (!$data) {
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
if ($this->type == 'contract_template_obligation') {
|
|
foreach ($value as $key => $row) {
|
|
if(!empty($row)) {
|
|
$id = Hasher::decode('contract_template_obligations', $row);
|
|
$data = ContractTemplateObligation::
|
|
where('id', $id)
|
|
->where('user_id', Auth::guard('user-api')->user()->id)
|
|
->count();
|
|
if (!$data) {
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* Get the validation error message.
|
|
*
|
|
* @return string
|
|
*/
|
|
public function message()
|
|
{
|
|
return config('error_code.under_error');
|
|
}
|
|
}
|