Thursday, 8 June 2017

uploading image to database and file using laravel 5

it is pretty much simple, ake a look at this controller function and if you dont understand it, just drop a comment and will send you the whole source code.

public function insertproduct(Request $request){
        $data=$request->all();
            $file=$request->file('image');
             // dd($request);
      
            $imageName=$file->getClientOriginalName();

            $file->move('products',$imageName);
            $data['image']=$imageName;
            // dd($imageName);
       

          DB::table('tbl_products')->insert(array(
          'prod_name' => $data['prod_name'],
          'Description' => $data['Description'],
          'Specifications'=>$data['Specifications'],
          'prodbrand_id'=>$data['prodbrand_id'],
          'prod_cat_id'=>$data['prod_cat_id'],
          'price'=>$data['price'],
          'discount'=>$data['discount'],
          'image'=>$data['image']
         
        ));



hope it works for you now :D