for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Spatie\ValidationRules\Rules;
use Illuminate\Contracts\Validation\Rule;
class ModelsExist implements Rule
{
/** @var string */
protected $modelClassName;
protected $attribute;
public function __construct(string $modelClassName, string $attribute = 'id')
$this->modelClassName = $modelClassName;
$this->attribute = $attribute;
}
public function passes($attribute, $value)
$value = array_filter($value);
$modelIds = array_unique($value);
$modelCount = $this->modelClassName::whereIn($this->attribute, $modelIds)->count();
whereIn
$this->modelClassName
string
Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.
return count($modelIds) === $modelCount;
public function message()
return __('validationRules.model_ids');
Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.