Snapey
Snapey
3 weeks ago (708,325 XP)

Can't see anything wrong there.

Try with your dd at the top of the request.

How come your form posts to '/success' but the method is postProduct ?

Do you submit the form with traditional post or are you submitting with ajax

splendidkeen

Solution:

Controller:

foreach ($request->images as $image) {
                        
                        $business = Auth::user();
                        $filename = time() . '.' . $image->getClientOriginalExtension();
                        $location = public_path('uploads/'. $filename );          
                        Image::make($image)->resize(812, null, function ($constraint){$constraint->aspectRatio();})->save($location);
                
                    $pictures[] = new Picture(['product_image' => $filename]);

                    }

                    $product->pictures()->saveMany($pictures);

Picture.php

public function product(){
        return $this->belongsTo(Product::class);
}

Product.php

public function pictures(){
          return $this->hasMany(Picture::class);
}

Pictures Table:

 Schema :: create ('pictures', function(Blueprint $table){
            $table->increments('id');
            $table->unsignedInteger('product_id'); // 
            $table->string('product_image')->default('productdefault.jpg');
            $table->timestamps();
 });
Snapey
Snapey
3 weeks ago (708,325 XP)

Great. How did you manage to get the images? I can't see anything here that would resolve the problem?

splendidkeen

Update above @Snapey

Please sign in or create an account to participate in this conversation.