Level 104
There's an errant space in the key 'state.municipality_id ' in your validation rules
1 like
Hi! I'm facing this issue and I do not know how to solve it, what I´m doing a create form so in the mount I use this.
public function mount(Institution $institution)
{
can('institution create');
$this->state = $institution;
$this->state['department_id'] = 1;
$this->route = url()->previous();
$this->fillSelect();
}
Then, the fill->select() method is as this
public function fillSelect()
{
$this->departments = Department::orderBy('department', 'asc')->get();
$this->municipalities = Municipality::where('department_id', '=', $this->state['department_id'])->orderBy('municipality', 'asc')->get();
}
In the blade template I have two select one is being filled depending in the other select. So to that is use the "updatedFoo" method by livewire
public function updatedStateDepartmentId()
{
$this->fillSelect();
}
Everything is ok but then I also have an image input, so when I wanted to upload an image it throws the error
Livewire\Exceptions\CannotBindToModelDataWithoutValidationRuleException
Cannot bind property [state.municipality_id] without a validation rule present in the [$rules] array on Livewire component: [institutions.institution-create-or-update].
I have tried creating the rules function but It always throws the error
public function rules()
{
return [
'state.institution_id' => 'required',
'state.institution_name' => 'required',
'state.department_id' => 'required',
'state.acronym' => 'required',
'state.institution_landline_phone_number' => 'required',
'state.institution_mobile_phone_number' => 'required',
'state.institution_email' => 'required',
'state.address' => 'required',
'state.start_date' => 'required',
'state.logo_url' => 'required',
'state.municipality_id ' => 'required',
];
}
The select inputs
<!-- Departamento-->
<div class="col-md-6 mb-3">
<span class="text-danger">*</span>
<x-jet-label for="department" value="Departamento:" />
<select id="department" type="text" wire:model="state.department_id"
class="form-control input-light {{ $errors->has('state.department_id') ? 'is-invalid' : '' }}">
@foreach ($departments as $item)
<option value="{{ $item->id }}">{{ $item->department }}</option>
@endforeach
</select>
<x-jet-input-error for="state.department_id" />
</div>
<!-- Municipio -->
<div class="col-md-6 mb-3" wire:loading.class="point">
<span class="text-danger">*</span>
<x-jet-label for="muni" value="Municipio:" />
<select id="muni" type="text" wire:model.defer="state.municipality_id"
class="form-control input-light {{ $errors->has('state.municipality_id') ? 'is-invalid' : '' }}">
<option>Seleccione Municipio</option>
@foreach ($municipalities as $item)
<option value="{{ $item->id }}">{{ $item->municipality }}</option>
@endforeach
</select>
<x-jet-input-error for="state.municipality_id" />
</div>
The image input
<!-- LOGO -->
<div class="col-md-12 mb-3 d-flex flex-row" x-data="{ isUploading: false, progress: 0 }"
x-on:livewire-upload-start="isUploading = true" x-on:livewire-upload-finish="isUploading = false"
x-on:livewire-upload-error="isUploading = false"
x-on:livewire-upload-progress="progress = $event.detail.progress">
<button type="button" id="btnLogo" class="btn-file blue-secondary boton-adjuntar">
<span class="text-danger">*</span>
<x-jet-label>Adjunte el logo de la institución</x-jet-label>
<span class="hint--right hint--info hint--medium blue-secondary"
aria-label="Ancho: 150px a 200px Alto: 50 px a 100 px Peso: maximo de 1 mb Formato: PNG - JPG">
<i class="fas fa-info-circle"></i>
</span>
<i class="fas fa-solid fa-image ml-4" id="btnIcon">
<input wire:model.defer="logo_temp"
class="input-adjuntar {{ $errors->has('logo_temp') ? 'is-invalid' : '' }}"
id="logo_temp" name="logo_temp" type="file" name="file" accept="image/*"
style="opacity:0;" />
<x-jet-input-error for="logo_temp" />
</i>
</button>
<div class="col-md-6">
<!-- Progress Bar -->
<div x-show="isUploading">
<progress max="100" x-bind:value="progress"></progress>
</div>
@if ($logo_temp != $state->logo)
<img class="img-thumbnail" width="200" height="auto"
src="{{ $logo_temp->temporaryUrl() }}" alt="{{ $name }}">
@elseif($state->logo)
<img class="img-thumbnail" width="200" height="auto"
src="{{ asset('storage/' . $state->logo) }}" alt="{{ $name }}" />
@endif
</div>
</div>
There's an errant space in the key 'state.municipality_id ' in your validation rules
Please or to participate in this conversation.