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)
    {
        $item = $request->validate([
            'product_name' => 'required',
            'product_price' => 'required|numeric'
        ]);
        $date = new Carbon;
        $item['product_name'] = $product_name = $request->product_name;
        $item['product_price'] = $request->product_price;
        $item['product_code'] = str_replace(':', '', $date->setTimezone('Asia/Jakarta')->toTimeString()) . '-' . Str::slug($product_name);
        $item['created_at'] = $date->now();
        Product::create($item);
        return redirect()->route('product.index');
    }
public function store ( Request $ request ) { $ item = $ request -> validate ( [ 'product_name' => 'required' , 'product_price' => 'required|numeric' ] ) ; $ date = new Carbon ; $ item [ 'product_name' ] = $ product_name = $ request -> product_name ; $ item [ 'product_price' ] = $ request -> product_price ; $ item [ 'product_code' ] = str_replace ( ':' , '' , $ date -> setTimezone ( 'Asia/Jakarta' ) -> toTimeString ( ) ) . '-' . Str :: slug ( $ product_name ) ; $ item [ 'created_at' ] = $ date -> now ( ) ; Product :: create ( $ item ) ; return redirect ( ) -> route ( 'product.index' ) ; }
Store a newly created resource in storage.
Store a newly created resource in storage .