store images into database laravel 8

  api, file-upload, laravel, php

i have a product and i want it to have multiple file, so i made a oneToMany relation between product and images model.
i was able to upload image successfully

    public function uploadFile(Request $request)
            foreach($request->file('images') as $file)
                $file->store('public/images/'. $file->getClientOriginalName());
        return $request->file('images');

now images are storage into storage/public/~ i want to them them to database
Here is my store function in ProductController

public function store(Request $request)
            'name' => 'required',
            'price' => 'required|numeric',
            'description' => 'required',
            'category' => 'required',
            'attribute' => 'required',
            'stocks' => 'required|numeric',
            //'discounts' => 'required|numeric'

        $product = Product::create($request->only('name','price','description', 'tag', 'category', 'attribute'));
            'quantity' => $request->stocks,
            'product_id' => $product->id

            //'discount' => $request->discounts,
            'product_id' => $product->id

foreach( $request->file('images') as $file)
                    'product_id' => $product->id,
                    'file_path'  => $file->hashName()


what should i add to it so i be able to store image into the table

Source: Laravel

Leave a Reply