51 lines
993 B
PHP
Executable File
51 lines
993 B
PHP
Executable File
<?php
|
|
|
|
namespace App\Rules;
|
|
|
|
use Illuminate\Contracts\Validation\Rule;
|
|
use App\LoyaltyCard;
|
|
|
|
class SignUpMobile implements Rule
|
|
{
|
|
|
|
|
|
/**
|
|
* Create a new rule instance.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function __construct()
|
|
{
|
|
|
|
}
|
|
|
|
/**
|
|
* Determine if the validation rule passes.
|
|
*
|
|
* @param string $attribute
|
|
* @param mixed $value
|
|
* @return bool
|
|
*/
|
|
public function passes($attribute, $value)
|
|
{
|
|
$mobile = strlen($value) == 12 ? $value : '63'.$value;
|
|
|
|
$loyaltyCard = LoyaltyCard::where('mobile',$mobile)
|
|
->where('is_active',1)
|
|
->where('cyware_synced',1)
|
|
->count();
|
|
|
|
return ($loyaltyCard > 0) ? false : true;
|
|
}
|
|
|
|
/**
|
|
* Get the validation error message.
|
|
*
|
|
* @return string
|
|
*/
|
|
public function message()
|
|
{
|
|
return 'Mobile Number already exists';
|
|
}
|
|
}
|