how to solve problems of deleting from orders or products

Posted 4 months ago by AndreLan

I want something I do not know how to write it correctly, I want when a customer delete an order and it is only one order (quantity = 1), to be deleted permanently and also if he typed the same quantity, to be deleted permanently also because when I tested this function I found that it keeps deleting till 2, 1, 0, -1, -2, -3, etc.. and increases the product quantity

and I want if the product quantity is 0 to hide the product for all users except the admins and the seller who sold it or at least to hide the Add to Cart button for all or replace it with dead button with out of stock instead of Add to Cart and if a user already ordered some of this product he cannot update quantity but can cancel it then it will be added to products again..

and I hope if someone tells me how to use these spans when errors happened or not because I do not know how to do that also or how to edit the default laravel error messages thanks, again...

this is the OrderController destroy function

public function destroy(Request $request, $id)
            {
            $validator = Validator::make($request->all(), [
                'qty' => 'required|max:255',

            ]);

            if ($validator->fails()) {
                return redirect('')
                            ->withErrors($validator)
                            ->withInput();
            }
            $order = Order::find($id);
        $product= Product::find($order->product_id);
        $order->qty = $order->qty - $request->input('qty');
        $product->inv = $product->inv + $order->qty;
        $product->save();
        $order->save();
            return redirect('/myorders');

        }  

and this is the span messages I want to run

<span class="help-block">
                  <div class="success_message" style="display: block; text-align:center">Order Updated Successfully</div><br>
            </span>   
            <span class="help-block">  
                  <strong class="error_message" style="display: block; text-align:center">Sorry, Product Out of Stock, Try again later</strong>
            </span>

Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.