Custom Validation Rules in request

Good afternoon! I'm trying to apply my rules in request, but he doesn't see them. Just saves.
12 Replies
trompix
trompix2y ago
Hro
Hro2y ago
Hey @User142 I will take a look at this
Hro
Hro2y ago
<?php

namespace App\Rules;

use Illuminate\Contracts\Validation\Rule;

class DummyRule implements Rule
{
public function __construct()
{
}

public function passes($attribute, $value): bool
{
return false;
}

public function message(): string
{
return 'The dummy role did not validate';
}
}
<?php

namespace App\Rules;

use Illuminate\Contracts\Validation\Rule;

class DummyRule implements Rule
{
public function __construct()
{
}

public function passes($attribute, $value): bool
{
return false;
}

public function message(): string
{
return 'The dummy role did not validate';
}
}
public function rulesForUpdate()
{
return $this->rulesForTranslatedFields([], ['description' => [new DummyRule()]]);
}
public function rulesForUpdate()
{
return $this->rulesForTranslatedFields([], ['description' => [new DummyRule()]]);
}
Hro
Hro2y ago
This seems to work. Not sure if there's a difference with what you are doing. Except that I did not use the invokableRule
trompix
trompix2y ago
@Harings Rob Can i ask you? What if you refresh the page and immediately click save? Are you saving successfully? If I click on the field then the check will work.
trompix
trompix2y ago
Hro
Hro2y ago
I cannot see that video. But after refresh, when clicking save, it does validate.
trompix
trompix2y ago
@Harings Rob Is it possible to poll the field to change it to a WYSIWYG editor? Will your validation also throw an error that the field is empty?
Hro
Hro2y ago
Hro
Hro2y ago
I can do whatever I want in this rule, even if the field is a wysiwyg
trompix
trompix2y ago
By the way, thanks for the replies. But some strange behavior in the fields. If I refresh the page and try to save it, it remains calm (I connected xdebug and it does not capture data as if the rule is being ignored). If I try to write something and then erase everything, then only then my rule is applied, as if the field does not see. I did the validation like this public function rulesForCreate(): array { return $this->rulesForTranslatedFields([], [ 'city' => ['required', new RequiredWysiwyg], ]); } public function rulesForUpdate(): array { return $this->rulesForTranslatedFields([], [ 'city' => ['required', new RequiredWysiwyg], ]); } And now, in any case, if the field is empty, then an error occurs.
Hro
Hro2y ago
Hey @User142 I have checked again, created a new content, and saved without touching the wysiwyg field and my rule validates. Maybe I am not understanding what you are saying?