app/Http/Controllers/CashierController.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)
    {
        $transaction = $request->validate([
            'customer' => 'required',
        ]);
        $item = $request->validate([
            'product_id' => 'required|numeric',
            'product_quantity' => 'required|numeric',
            'customer' => 'required'
        ]);
        $date = new Carbon;
        $price = $request->product_price;
        $quantity = $request->product_quantity;
        $total = $price * $quantity;
        $total_price = null;
        if ($total >= 50000) {
            $diskon = $total * 10 / 100;
            $total_price = $total - $diskon;
        }
        $transaction = Transaction::create([
            'total_price' => $total_price,
            'customer' => $request->customer,
            'id_admin' => auth()->user()->id,
            'created_at' => $date->now()
        ]);
        $item['id_transaction'] = $transaction->id;
        $item['id_product'] = $request->product_id;
        $item['quantity'] = $quantity;
        $item['subtotal_price'] = $total;
        $item['created_at'] = $date->now();
        TransactionDetail::create($item);
        return redirect()->route('cashier.index');
    }
public function store ( Request $ request ) { $ transaction = $ request -> validate ( [ 'customer' => 'required' , ] ) ; $ item = $ request -> validate ( [ 'product_id' => 'required|numeric' , 'product_quantity' => 'required|numeric' , 'customer' => 'required' ] ) ; $ date = new Carbon ; $ price = $ request -> product_price ; $ quantity = $ request -> product_quantity ; $ total = $ price * $ quantity ; $ total_price = null ; if ( $ total >= 50000 ) { $ diskon = $ total * 10 / 100 ; $ total_price = $ total - $ diskon ; } $ transaction = Transaction :: create ( [ 'total_price' => $ total_price , 'customer' => $ request -> customer , 'id_admin' => auth ( ) -> user ( ) -> id , 'created_at' => $ date -> now ( ) ] ) ; $ item [ 'id_transaction' ] = $ transaction -> id ; $ item [ 'id_product' ] = $ request -> product_id ; $ item [ 'quantity' ] = $ quantity ; $ item [ 'subtotal_price' ] = $ total ; $ item [ 'created_at' ] = $ date -> now ( ) ; TransactionDetail :: create ( $ item ) ; return redirect ( ) -> route ( 'cashier.index' ) ; }
Store a newly created resource in storage.
Store a newly created resource in storage .
// $transaction['total_price'] = $total_price; // $transaction['customer'] = $request->customer; // $transaction['id_admin'] = auth()->user()->id; // $transaction['created_at'] = $date->now();