Search code examples
laravellaravel-8laravel-livewire

why my validation doesen't work properly?


i'm working on a Laravel/Livewire project and my validation don't let my form to submit but errors are not shown in my blade .

i implemented my validation system same as Livewire documentation but it didn't work for me

even i tested some other ways like validator::make() but my bug didn't solved

my controller :

class Index extends Component
{
    use WithPagination;

    public $title, $en_title, $parent;

    protected $rules = [
        'title' => 'required',
        'en_title' => 'required',
    ];

    protected $paginationTheme = "bootstrap";

    public function store()
    {
        $validate = $this->validate();

        Category::create([
            'title' => $this->title,
            'en_title' => $this->en_title,
            'parent_id' => $this->parent,
        ]);

        $this->reset(['title', 'en_title', 'parent']);
        session()->flash('add_category', 'دسته بندی با موفقیت اضافه شد');
    }
}

my blade :

<form wire:submit.prevent="store" class="col-md-6">
    <div>
        <div class="form-group">
            <label class="form-label">عنوان دسته بندی</label>
            <input wire:model.defer="title" type="text" class="form-control" placeholder="نام دسته بندی">
            @error('title') <div class="invalid-feedback">{{$message}}</div> @enderror
        </div>

        <div class="form-group">
            <label class="form-label">title</label>
            <input wire:model.defer="en_title" type="text" class="form-control" placeholder="عنوان انگلیسی دسته بندی">
            @error('en_title') <div class="invalid-feedback">{{$message}}</div> @enderror
        </div>

        <div class="form-group">
            <label class="form-label">دسته بندی والد</label>
            <select wire:model.defer="parent" id="select-countries" class="form-control custom-select">
                <option value="">بدون والد</option>
                @foreach($categoriesCreate as $category)
                    <option value="{{$category->id}}">{{$category->title}}</option>
                    @if (count($category->childrenRecursive) > 0)
                        @include('layouts.partials', ['categories' => $category->childrenRecursive, 'level'=> 1, 'create' => 1])
                    @endif
                @endforeach
            </select>
        </div>
    </div>

    <div class="form-group">
        <button type="submit" class="btn btn-success mt-1 mb-1">افزودن</button>

        <div wire:loading wire:target="store">
            <div class="loader-wrapper d-flex justify-content-center align-items-center">
                <div class="loader">
                    <div class="ball-pulse">
                        <div></div>
                        <div></div>
                        <div></div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</form>

Solution

  • i don't know why but i removed invalid_feedback class from my @error() in my blade that related to bootstrap and my errors are shown