app/Http/Controllers/ProductController.php
/**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
Store a newly created resource in storage.
Store a newly created resource in storage .
public function store(Request $request)
    {
        $request->validate([
            'code_sku' => 'required',
            'name' => 'required',
            'photo'=> 'image|nullable|max:1999'
        ]);
        if ($request->hasFile('photo')) {
            $filenameWithExt = $request->file('photo')->getClientOriginalName();
            $filename = pathinfo($filenameWithExt,PATHINFO_FILENAME);
            $extension = $request->file('photo')->getClientOriginalExtension();
            $fileNameToStore = $filename.'_'.time().'.'.$extension;
            $path = $request->file('photo')->storeAs('public/photo',$fileNameToStore);
        } else {
            $fileNameToStore = 'noimage.jpg';
        }
        $product = new Product();
        $product->code_sku= $request->code_sku;
        $product->name= $request->name;
        $product->description= $request->description;
        $product->hs_code= $request->hs_code;
        $product->hs_code_bd= $request->hs_code_bd;
        $product->photo=$fileNameToStore;
        $product->unit= $request->unit;
        $product->net_weight= $request->net_weight;
        $product->gross_weight= $request->gross_weight;
        $product->cbm= $request->cbm;
        $product->product_cost= $request->product_cost;
        $product->packing_cost= $request->packing_cost;
        $product->cash_incentive= $request->cash_incentive;
        $product->save();
        Product::create($request->all());
        return redirect()->route('product.index')
            ->with('success', 'New product Created successfully');
    }
public function store ( Request $ request ) { $ request -> validate ( [ 'code_sku' => 'required' , 'name' => 'required' , 'photo' => 'image|nullable|max:1999' ] ) ; if ( $ request -> hasFile ( 'photo' ) ) { $ filenameWithExt = $ request -> file ( 'photo' ) -> getClientOriginalName ( ) ; $ filename = pathinfo ( $ filenameWithExt , PATHINFO_FILENAME ) ; $ extension = $ request -> file ( 'photo' ) -> getClientOriginalExtension ( ) ; $ fileNameToStore = $ filename . '_' . time ( ) . '.' . $ extension ; $ path = $ request -> file ( 'photo' ) -> storeAs ( 'public/photo' , $ fileNameToStore ) ; } else { $ fileNameToStore = 'noimage.jpg' ; } $ product = new Product ( ) ; $ product -> code_sku = $ request -> code_sku ; $ product -> name = $ request -> name ; $ product -> description = $ request -> description ; $ product -> hs_code = $ request -> hs_code ; $ product -> hs_code_bd = $ request -> hs_code_bd ; $ product -> photo = $ fileNameToStore ; $ product -> unit = $ request -> unit ; $ product -> net_weight = $ request -> net_weight ; $ product -> gross_weight = $ request -> gross_weight ; $ product -> cbm = $ request -> cbm ; $ product -> product_cost = $ request -> product_cost ; $ product -> packing_cost = $ request -> packing_cost ; $ product -> cash_incentive = $ request -> cash_incentive ; $ product -> save ( ) ; Product :: create ( $ request -> all ( ) ) ; return redirect ( ) -> route ( 'product.index' ) -> with ( 'success' , 'New product Created successfully' ) ; }
Store a newly created resource in storage.
Store a newly created resource in storage .
// Get filename with the extension // Get just filename // Get just ext // Filename to store // Upload Image