app/Http/Controllers/OrderController.php
/**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
Update the specified resource in storage.
Update the specified resource in storage .
public function update(Request $request, $id)
    {
        $result = (new Order)->fetch($id);
        if(!$result) {
            $message = __('common.invalid_id', ['attr' => __('order.order')]);
            return jsonResponse(false, 207, $message);
        }
        $inputs = $request->all();
        $validation = (new Order)->validation($inputs, $id);
        if($validation->fails()) {
            return jsonResponse(false, 206, $validation->getMessageBag());
        }
        try {
            \DB::beginTransaction();
            if($inputs['order_status'] == 2) { 
                $inputs['updated_by'] = authId();
                (new Order)->store($inputs, $id);
                $detail = (new OrderDetail)->customerOrder($result->id);
                $email = $result->email;
                $subject = 'Fashion waves: Order Confirmed #' . $result->order_number;
                \Mail::send('front2.order-mail', compact('result', 'detail'), function($message) use ($subject, $email){
                    $message->from(env('MAIL_FROM_EMAIL'), env('MAIL_FROM_NAME'));
                    $message->to($email, $email);
                    $message->subject($subject);
                });            
            }
            \DB::commit();
            $extra = ['redirect' => route('order.index')];
            $message = 'Order has been confirmed successfully!';
            return jsonResponse(true, 201, $message, $extra);
        }
        catch (\Exception $e) {
            \DB::rollBack();
            return jsonResponse(true, 207, __('message.server_error') . $e->getMessage() . $e->getFile() . $e->getLine());
        }
    }
public function update ( Request $ request , $ id ) { $ result = ( new Order ) -> fetch ( $ id ) ; if ( ! $ result ) { $ message = __ ( 'common.invalid_id' , [ 'attr' => __ ( 'order.order' ) ] ) ; return jsonResponse ( false , 207 , $ message ) ; } $ inputs = $ request -> all ( ) ; $ validation = ( new Order ) -> validation ( $ inputs , $ id ) ; if ( $ validation -> fails ( ) ) { return jsonResponse ( false , 206 , $ validation -> getMessageBag ( ) ) ; } try { \ DB :: beginTransaction ( ) ; if ( $ inputs [ 'order_status' ] == 2 ) { $ inputs [ 'updated_by' ] = authId ( ) ; ( new Order ) -> store ( $ inputs , $ id ) ; $ detail = ( new OrderDetail ) -> customerOrder ( $ result -> id ) ; $ email = $ result -> email ; $ subject = 'Fashion waves: Order Confirmed #' . $ result -> order_number ; \ Mail :: send ( 'front2.order-mail' , compact ( 'result' , 'detail' ) , function ( $ message ) use ( $ subject , $ email ) { $ message -> from ( env ( 'MAIL_FROM_EMAIL' ) , env ( 'MAIL_FROM_NAME' ) ) ; $ message -> to ( $ email , $ email ) ; $ message -> subject ( $ subject ) ; } ) ; } \ DB :: commit ( ) ; $ extra = [ 'redirect' => route ( 'order.index' ) ] ; $ message = 'Order has been confirmed successfully!' ; return jsonResponse ( true , 201 , $ message , $ extra ) ; } catch ( \ Exception $ e ) { \ DB :: rollBack ( ) ; return jsonResponse ( true , 207 , __ ( 'message.server_error' ) . $ e -> getMessage ( ) . $ e -> getFile ( ) . $ e -> getLine ( ) ) ; } }
Update the specified resource in storage.
Update the specified resource in storage .
// confirm order // order code start // order code end // detail code start // detail code end // send mail code start // send mail code end