Files
docker-rconfig/app/Rules/CategoryHasCommands.php
2024-10-19 18:23:55 +00:00

51 lines
930 B
PHP

<?php
namespace App\Rules;
use App\Models\Category;
use Illuminate\Contracts\Validation\Rule;
class CategoryHasCommands 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)
{
if ($value == null) {
return false;
}
$result = Category::with('command')->find($value);
if ($result === null) {
return false;
}
return $result->command->count() > 0;
}
/**
* Get the validation error message.
*
* @return string
*/
public function message()
{
return 'A category must have commands associated with it.';
}
}