Support the ongoing development of Laravel.io →
posted 9 years ago
Database
Last updated 2 years ago.
0

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;
Last updated 9 years ago.
0

Thank you astroanu it's works fine for me, thanks alot.

0

^_^ good to know

0

Sign in to participate in this thread!

Eventy

Your banner here too?

yokeswar yokeswar Joined 9 Oct 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.