ifox
05/19/2022, 12:27 PMphp
$page = $repository->forSlug($slug);
$validator = new FormValidator($page->blocks, request()->all());
$fields = $validator->validate();
php
/**
* Validate all fields. On success, return the prepared fields as a collection.
*
* @throws \Illuminate\Validation\ValidationException
*/
public function validate(): Collection
{
$fields = collect($this->fieldBlocks)->map(fn ($block) => $this->getField($block));
$this->validateFields($fields);
return $fields;
}ifox
05/19/2022, 12:29 PMkalle
05/19/2022, 12:34 PMifox
05/19/2022, 12:36 PMifox
05/19/2022, 12:36 PMifox
05/19/2022, 12:36 PMkalle
05/19/2022, 12:38 PMifox
05/19/2022, 12:39 PM24C Felix
05/19/2022, 12:59 PMifox
05/19/2022, 1:06 PMphp
protected function validateFields(Collection $fields)
{
$rules = [];
$customAttributes = [];
foreach ($fields as $field) {
if ($rule = $field->rule()) {
$rules[$field->key()] = $rule;
}
$customAttributes[$field->key()] = $field->label();
}
Validator::make($this->data, $rules, [], $customAttributes)->validate();
foreach ($fields as $field) {
$field->afterValidation();
}
}ifox
05/19/2022, 1:08 PMrule() method, by default it just does this but then on each field you can add more rules:
php
public function rule(): string
{
if ($this->block->content['required'] ?? false) {
return 'required';
}
return 'nullable';
}ifox
05/19/2022, 1:09 PMphp
public function rule(): string
{
return implode('|', [parent::rule(), 'file']);
}ifox
05/19/2022, 1:10 PMkalle
05/19/2022, 1:45 PMifox
05/19/2022, 1:46 PMkalle
05/19/2022, 1:47 PM24kappa
05/19/2022, 2:21 PMtenZdenda
05/19/2022, 2:40 PMkalle
05/19/2022, 2:56 PMifox
05/19/2022, 3:03 PMifox
05/19/2022, 3:03 PM24kappa
05/19/2022, 4:30 PMifox
05/19/2022, 5:10 PMifox
05/19/2022, 5:11 PMtenZdenda
05/19/2022, 6:16 PMifox
05/19/2022, 8:55 PMdakaalim
05/19/2022, 9:05 PM$repository->images('list_of_images') when I call this, it returns images for both locale, how can I make it return only images for the current set locale?24kappa
05/20/2022, 8:34 AMgiuseppemastrodonato
05/20/2022, 8:57 AM