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)
    {
        $this->validate($request,[
            'p_name' => 'required',
            'p_price' => 'required',
            'p_link' => 'required',
            'p_disc' => 'required',
        ]);
        if($request->hasfile('p_image')) {
            $filenameWithExt = $request->file('cover_image')->getClientOriginalName();
            $filename =  pathinfo($filenameWithExt, PATHINFO_FILENAME);
            $extention = $request->file('p_image')->getClientOriginalExtension();
            $filenametostore = $filename . '_' . time() . '.' . $extention;
            $path = $request->file('cover_image')->storeAs('public/product_images', $filenametostore);
        }
        else {
            $filenametostore = $request->input('p_image');
        }
        $category = $request->input('p_category');
        $preview =  $request->input('preview_image');
        $options['key'] =  $request->input('preview_image');
        if($category == null && $request->input('p_categorytext') == null){
            return redirect()->back()->with('error', 'Select or put the product category')->withInput();
        }
        else {
            if($category == !null) {
                $category = $request->input('p_category');
            }
            else {
                $category = $request->input('p_categorytext');
            }
        }
        $product = new Products;
        $product->product_code = 'LS' . '_'  .  str_random(2) . '-' . str_random(5) . '_' . 'serial_code';
        $product->name = $request->input('p_name');
        $product->price = $request->input('p_price');
        $product->discount = $request->input('p_discount');
        $product->cover_image = $filenametostore;
        $product->preview_image = json_encode($options['key']);
        $product->discription = $request->input('p_disc');
        $product->featured = $request->input('p_feature');
        $product->category = $category;
        $product->link = $request->input('p_link');
        $product->save();
        return redirect()->route('shop.product_list')->with('success', 'Product Created');
    }
public function store ( Request $ request ) { $ this -> validate ( $ request , [ 'p_name' => 'required' , 'p_price' => 'required' , 'p_link' => 'required' , 'p_disc' => 'required' , ] ) ; if ( $ request -> hasfile ( 'p_image' ) ) { $ filenameWithExt = $ request -> file ( 'cover_image' ) -> getClientOriginalName ( ) ; $ filename = pathinfo ( $ filenameWithExt , PATHINFO_FILENAME ) ; $ extention = $ request -> file ( 'p_image' ) -> getClientOriginalExtension ( ) ; $ filenametostore = $ filename . '_' . time ( ) . '.' . $ extention ; $ path = $ request -> file ( 'cover_image' ) -> storeAs ( 'public/product_images' , $ filenametostore ) ; } else { $ filenametostore = $ request -> input ( 'p_image' ) ; } $ category = $ request -> input ( 'p_category' ) ; $ preview = $ request -> input ( 'preview_image' ) ; $ options [ 'key' ] = $ request -> input ( 'preview_image' ) ; if ( $ category == null && $ request -> input ( 'p_categorytext' ) == null ) { return redirect ( ) -> back ( ) -> with ( 'error' , 'Select or put the product category' ) -> withInput ( ) ; } else { if ( $ category == ! null ) { $ category = $ request -> input ( 'p_category' ) ; } else { $ category = $ request -> input ( 'p_categorytext' ) ; } } $ product = new Products ; $ product -> product_code = 'LS' . '_' . str_random ( 2 ) . '-' . str_random ( 5 ) . '_' . 'serial_code' ; $ product -> name = $ request -> input ( 'p_name' ) ; $ product -> price = $ request -> input ( 'p_price' ) ; $ product -> discount = $ request -> input ( 'p_discount' ) ; $ product -> cover_image = $ filenametostore ; $ product -> preview_image = json_encode ( $ options [ 'key' ] ) ; $ product -> discription = $ request -> input ( 'p_disc' ) ; $ product -> featured = $ request -> input ( 'p_feature' ) ; $ product -> category = $ category ; $ product -> link = $ request -> input ( 'p_link' ) ; $ product -> save ( ) ; return redirect ( ) -> route ( 'shop.product_list' ) -> with ( 'success' , 'Product Created' ) ; }
Store a newly created resource in storage.
Store a newly created resource in storage .
// return ; // return  $category; // foreach(array($options['key']) as $key => $img_preview) { //     $product->preview_image = $img_preview; // }