skip to Main Content

my component livewire

 public $images = [];

    public function rules()
    {
        return [
            'images.*.name' => 'required|max:255',
        ];
    }

blade.php

            <div id="images">
                @foreach($images as $index => $image)
                    <div class="card" wire:key="image-field-{{$images[$index]['id']}}">
                        <img src="{{$images[$index]->original_url}}" class="card-img-top" alt="{{$images[$index]->name}}" />
                        <input type="text" name="item-{{$index}}-name" id="item.{{$index}}.name" wire:model="images.{{$index}}.name" />
                        <div class="card-footer">
                            <button wire:click="changeImageName({{$image['id']}},{{$images[$index]['name']}})">Update</button>
                            {{$images[$index]->name}}
                        </div>
                    </div>
                @endforeach
            </div>

so wire:model="images.{{$index}}.name" not working, not changing after typing

and update will error

Uncaught SyntaxError: identifier starts immediately after numeric literal

2

Answers


  1. Chosen as BEST ANSWER

    Make function update fix my problem

    public function updated($name, $value)
    {
        foreach($this->images as $image){
            $i = Image::find($image['id']);
            $i->name = $image['name'];
            $i->update();
        }
    }
    

  2. Maybe try adding the multiple attribute in the input tag. and change the wire:model value to just have images

    <input type="text" ... wire:model='images' multiple />

    I Hope that helps

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search