app/Http/Controllers/TransactionController.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)
    {
        $car = Car::where('id',$request->car_id)->first();
        $rules = array(
            'customer_email' => 'required|email|max:255',
            'customer_name' => 'required|max:255',
            'customer_phone' => 'required|numeric',
            'car_id' => 'required|numeric',
        );
        $validator = Validator::make($request->all(), $rules);
        if ($validator->fails())
        {
            $messages = $validator->messages();
            return back()->with('error','Please check the form again');
        }else{
            $transaction = new Transaction();
            $transaction->car_id = $request->car_id;
            $transaction->customer_email = $request->customer_email;
            $transaction->customer_phone = $request->customer_phone;
            $transaction->customer_name = $request->customer_name;
            $transaction->total_price = $car->car_price;
            $transaction->save();
            $car->update([
                'car_stock' => $car->car_stock - 1
            ]);
            Mail::to($transaction->customer_email)->send(
                new TransactionInvoice($transaction)
            );
            return redirect()->route('transaction.index')->with('success','Data Transaction Successfully Added');
        }
    }
public function store ( Request $ request ) { $ car = Car :: where ( 'id' , $ request -> car_id ) -> first ( ) ; $ rules = array ( 'customer_email' => 'required|email|max:255' , 'customer_name' => 'required|max:255' , 'customer_phone' => 'required|numeric' , 'car_id' => 'required|numeric' , ) ; $ validator = Validator :: make ( $ request -> all ( ) , $ rules ) ; if ( $ validator -> fails ( ) ) { $ messages = $ validator -> messages ( ) ; return back ( ) -> with ( 'error' , 'Please check the form again' ) ; } else { $ transaction = new Transaction ( ) ; $ transaction -> car_id = $ request -> car_id ; $ transaction -> customer_email = $ request -> customer_email ; $ transaction -> customer_phone = $ request -> customer_phone ; $ transaction -> customer_name = $ request -> customer_name ; $ transaction -> total_price = $ car -> car_price ; $ transaction -> save ( ) ; $ car -> update ( [ 'car_stock' => $ car -> car_stock - 1 ] ) ; Mail :: to ( $ transaction -> customer_email ) -> send ( new TransactionInvoice ( $ transaction ) ) ; return redirect ( ) -> route ( 'transaction.index' ) -> with ( 'success' , 'Data Transaction Successfully Added' ) ; } }
Store a newly created resource in storage.
Store a newly created resource in storage .
// Send Email to Customer