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, Product $prod )
    {   
        $val=['pname' => 'required|max:15',
        'pdetail' => 'required|max:300',
        'pimage' => 'required|image|mimes:jpeg,png,jpg,gif,svg|max:2048',];
        $this->validate($request,$val);
        $prod->name=$request->pname;
        $prod->detail=$request->pdetail;
        if ($image = $request->file('pimage')) {
            $dest_Path = 'storage/app/image/';
            $prod_image = date('YmdHis') . "." . $image->getClientOriginalExtension();
            $image->move($dest_Path, $prod_image);
            $prod->image = "$prod_image";
        }
        $prod->save();
        return redirect('/')
        ->with('success','Product added successfully.');
    }
public function store ( Request $ request , Product $ prod ) { $ val = [ 'pname' => 'required|max:15' , 'pdetail' => 'required|max:300' , 'pimage' => 'required|image|mimes:jpeg,png,jpg,gif,svg|max:2048' , ] ; $ this -> validate ( $ request , $ val ) ; $ prod -> name = $ request -> pname ; $ prod -> detail = $ request -> pdetail ; if ( $ image = $ request -> file ( 'pimage' ) ) { $ dest_Path = 'storage/app/image/' ; $ prod_image = date ( 'YmdHis' ) . " . " . $ image -> getClientOriginalExtension ( ) ; $ image -> move ( $ dest_Path , $ prod_image ) ; $ prod -> image = " $ prod_image " ; } $ prod -> save ( ) ; return redirect ( '/' ) -> with ( 'success' , 'Product added successfully.' ) ; }
Store a newly created resource in storage.
Store a newly created resource in storage .
// $input = $request->all(); // if ($image = $request->file('pimage')) { //     $destinationPath = 'storage/app/image/'; //     $profileImage = date('YmdHis') . "." . $image->getClientOriginalExtension(); //     $image->move($destinationPath, $profileImage); //     $input['pimage'] = "$profileImage"; // } // Product::create($input); // return redirect()->route('/') //                 ->with('success','Product created successfully.');