Top 50

@SNAPEY - I used this
if (Auth::attempt(['email' => $email, 'password' => $password, 'active' => 1])) {
// The user is active, not suspended, and exists.
}
and I checked SQL query with Laravel Debugbar and I found that login check isn't using that code at all !!

@SIANGBOON - I checked this also and found that the admin who I use is the one who hit the function, and the user was changed to inactive ( 0 in the database) but can log in normally and use all functions normally

@SNAPEY - when you log in as an admin and change a user status to inactive it will be changed and also in the database but when you try to log in with this account it will work normally as it is active and nothing changed but actually it was changed even in the database

@arthvrian
the last 3 lines on cancel_qty are the rest of the old code :) ..., seriously I forgot removing them :D ...,
In the view, you are right I made it @else without ($order->qty > 1), it is logical :) ...,
@elseif ($order->qty > 1) //must be only @else
and I can't use it for updating because I am using another function to do that and it is completely different, also I prefer to make this with another button which increases the qty, but the second one is only decreasing the qty.
Now I have a new problem which is repeating the item if you updated its qty or added it again from the home view, I want to make it only one item with its qty if it was increased, not repeating it every time you increase qty...

@Snapey
Thanks for your consideration, although your code did not work with me it helped to think out of the box or( out of the OrderController ), I did what I want in the cart view and It worked :) ..
I will write the code...

@jlrdw
I thought about the first idea and tested it and the problem is when you delete the order with that special button you will lose the quantity and the product will not be increased, it will lose its inventory that was deleted permanently from the orders' cart..

then I canceled this idea...

a friend told me to hide the item if it = 0 by js, but I don't know how to do that, honestly I am not good at js, also I see that this is not a solution, because it still actually exists in the cart.

@Snapey
I told you I tried what you said before asking..., I tried dd() and it gave me true when deleting the value of the item's qty and the item stayed with qty=0, and the product increased by the same value you typed to delete from the order, it means that everything is ok, and I checked if the order was being loaded is the correct one, and about your code

if ($request->input('qty') >= $order->qty {
// deleting the same or more than the quantity ordered
// therefore order is no longer required
$order->delete();
return redirect('/my_cart')
}

it caused deleting the item with ignoring the value you typed whether less or more than the item's qty

public function destroy(Request $request, $id)
{
$validator = Validator::make($request->all(), [
'qty' => 'required|max:255',
]);
$order = Order::find($id);
// this to prevent negative values because after deleting all quantities of an item,
// the item stays in the cart with qty=0, so if you typed any number it will count with
// negative values and the product will be increased, I didn't get any idea to prevent that except this trick.
if ($request->input('qty') > $order->qty) {
return redirect('/my_cart')
->withErrors($validator)
->withInput();
}
// I tried this to get rid of the items with qty=0 by deleting them permanently if you
// typed a value=the existing qty or if the qty=1 and you clicked delete
// but I got this error (Can't use method return value in write context)
// when opening the cart view.
// if ($request->input('qty') = $order->qty || $request->input('qty') = 1) {
// return redirect('/my_cart')
// ->delete();
// }
// I tried this also for the same reason but I got this error
// (Trying to get property of non-object) when deleting.
// $order = Order::where('qty','=',$request->input('qty'))->delete();
// this is to increase the product inventory with the
// value you typed to delete from orders
$product= Product::find($order->product_id);
$product->inv = $product->inv + $request->input('qty');
// this is to delete only the qty you typed if you typed
// a value less than the existing qty of the item.
$order->qty = $order->qty - $request['qty'];
$product->save();
$order->save();
return redirect('/my_cart');
}

]);
$order = Order::find($id);
// this to prevent negative values because after deleting all quantities of an item,

// the item stays in the cart with qty=0, so if you typed any number it will count with
// negative values and the product will be increased, I didn't get any idea to prevent that except this trick.
if ($request->input('qty') > $order->qty) {
return redirect('/my_cart')
->withErrors($validator)
->withInput();
}

// I tried this to get rid of the items with qty=0 by deleting them permanently if you
// typed a value=the existing qty or if the qty=1 and you clicked delete
// but I got this error (Can't use method return value in write context)
// when opening the cart view.
// if ($request->input('qty') = $order->qty || $request->input('qty') = 1) {
// return redirect('/my_cart')
// ->delete();
// }

// I tried this also for the same reason but I got this error
// (Trying to get property of non-object) when deleting.
// $order = Order::where('qty','=',$request->input('qty'))->delete();

// this is to increase the product inventory with the
// value you typed to delete from orders
$product= Product::find($order->product_id);
$product->inv = $product->inv + $request->input('qty');

// this is to delete only the qty you typed if you typed
// a value less than the existing qty of the item.
$order->qty = $order->qty - $request['qty'];

When I delete from the item's quantity it works fine, I just click on delete then a pop-up input form will appear then I write the quantity I want to delete then submit.. for example, I have a watch in my cart with quantity=20, when I want to delete 5 of them I have to write 5 then delete and after that I will have the same item of course with quantity=15, but when I write 15 to delete the whole order it only deletes the quantity and leaves the item with quantity=0, also if the quntity=1 I want to delete the item permanently when clicking delete, I do not need the pop-up input form to appear.. how to do that. I tried both of the commented methods but with no result, only errors.

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...

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 -1 -2 -3 etc..

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 :D
thanks, again...

ok, thanks for all :) , I fixed it, It was the action of the view form :D
action="/update_order/{{ $order['id'] }}" , It should be action="/update_order/{{ $order->product->id }}" ,,

Now :)

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 -1 -2 -3 etc..

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 told me how to use the commented spans because I do not know how to do that also :D
thanks again..

what is wrong with this controller, I always get this error when update order "Trying to get property of non-object" ,(notice that I'm using the same function for store and it works fine, also 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 and I found that it keeps deleting till -1 -2 -3 etc..
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 told me how to use the commented spans because I do not know how to do that also :D
thanks

first of all, I'm a beginner so I'm still learning and I do not know if some of this is correct, all I want is when I press the buy button it will display the form and I will type the quantity then submit and my quantity will increase and the products inventory will decrease and if I deleted my order, The products will increase again (I did this and I think it will work) and the user can update his quantity and if someone ordered something the seller cannot delete it, only update his inventory as same as the buy button way and the form, and if the users ordered all products it will display (out of stock) with a dead link button, I am training, It is not homework and I do not know how to write all functions..