File: /mnt/data/ghayatcom/ghayatcom-api/app/Rules/TableCountNotZero.php
<?php
namespace App\Rules;
use DB;
use Illuminate\Contracts\Validation\Rule;
/**
* App\Rules
*
* @property string $table
*/
class TableCountNotZero implements Rule
{
/**
* Create a new rule instance.
*
* @return void
*/
public function __construct($table)
{
$this->table = $table;
}
/**
* Determine if the validation rule passes.
*
* @param string $attribute
* @param mixed $value
* @return bool
*/
public function passes($attribute, $value)
{
$count = DB::table($this->table)->count();
if ($count > 0) {
if (isset($value)) {
return true;
} else {
return true;
}
} else {
return true;
}
}
/**
* Get the validation error message.
*
* @return string
*/
public function message()
{
return ':Attribute is required';
}
}