php - Laravel file upload add to collection move file in numeric folder -


i made form can create product , upload multiple image product. works fine, except file being moved subfolder (corresponding id in media table in database)

enter image description here enter image description here

my controller :

    public function store(request $request) {     $product = new product;     [...]     $product->save();      foreach ($request->get('product_categories') $category_id) {         $product->categories()->attach($category_id);     }      $files = $request->file('product_images');     foreach($files $file) {         $product->addmedia($file)->tocollection('images');     }     return view('dashboard/create_product')->with('success', 1)->with('categories', category::get()); } 

the product model

class product extends model implements hasmedia {    use hasmediatrait, softdeletes;    public function images() {        return $this->hasmany("app/images");    }     public function categories()    {       return $this->belongstomany("app\category", 'category_product',    'product_id', 'category_id');    }     public function inventory()    {        return $this->hasone('app\inventory');    }     /**     * attributes should mutated dates.     *     * @var array     */    protected $dates = ['deleted_at']; } 

why moved in subfolder ? how can prevent this?

it looks file processed method ->addmedia()

this comes laravel package don't know about, should @ package's documentation regargind default path files stored.

check out : http://medialibrary.spatie.be/v3/advanced-usage/using-a-custom-directory-structure/


Comments