I would use Laravel's storage class, so in the future if you decide to move to the cloud you can do so .easily.
instead of sending the file on the form post data, upload images with ajax and insert a hidden input with the image id. <input type="hidden" name="image_ids[]" value="1">
Create a new model (image or something) then save each image on the db. so you can easily save images and product relationships in just one line.
class Product{
public function images()
{
return $this->belongsToMany(Image::class);
}
}
class Image{
public function product()
{
return $this->belongsToMany(Product::class);
}
public function getMediumUrlAttribute()
{
// return path to medium size file
}
}
$product->images()->sync($request::get('image_ids'));
echo $image->medium_url;
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community