For a better understanding, here are two of my models.
Model for images:
class Image extends Model
{
...
public function item()
{
return $this->belongsTo(Item::class);
}
}
Model an item:
class Item extends Model
{
...
public function images()
{
return $this->hasMany(Image::class);
}
}
In my view I am using a mixture of laravel's blade engine and Vue.js which looks like this:
<div class="form-group">
<label>@lang('app.user.edit.images')</label>
<div v-for="(img, index) in my.images">
<input type="text" name="images[]" class="form-control images" v-model="my.image">
</div>
</div>
This gives my one input for any image of the item. By changing the value of each image I want to update all database. I do not know if it is a good practice to name the input like name="images[]" to get an array.
My database table for images looks like this:
+----+---------+-------+------------+------------+
| id | item_id | image | created_at | updated_at |
+----+---------+-------+------------+------------+
Hopefully, some of you had the same problem in the past and can help me out.