Laravel 9 Ecom - Part 36: Shopping cart item Quantity increment decrement using Livewire Laravel 9

Поделиться
HTML-код
  • Опубликовано: 16 ноя 2024

Комментарии • 17

  • @fundaofwebit
    @fundaofwebit  2 года назад +3

    Hey guys, on Time: 13:50 to 14:25 on the video.
    There was a small correction: on decrementQuantity() function as follows:
    public function decrementQuantity(int $cartId)
    {
    $cartData = Cart::where('id',$cartId)->where('user_id', auth()->user()->id)->first();
    if($cartData)
    {
    if($cartData->quantity > 1){
    $cartData->decrement('quantity');
    $this->dispatchBrowserEvent('message', [
    'text' => 'Quantity Updated',
    'type' => 'success',
    'status' => 200
    ]);
    }else{
    $this->dispatchBrowserEvent('message', [
    'text' => 'Quantity cannot be less than 1',
    'type' => 'success',
    'status' => 200
    ]);
    }
    }else{
    $this->dispatchBrowserEvent('message', [
    'text' => 'Something Went Wrong!',
    'type' => 'error',
    'status' => 404
    ]);
    }
    }

    • @phoenixtulip5031
      @phoenixtulip5031 2 года назад +2

      if I didn't see this comment , I would tell you about this problem!
      Thanks you sir , for your tutorials !
      I will wait for more tutorials!

    • @brankoblesicjr.5792
      @brankoblesicjr.5792 2 года назад +1

      So, for decrementQuantity just to copy this uour code instead of the code from the video?

    • @fkwebdev
      @fkwebdev Год назад +1

      I already did it myself because I was facing this error after this I see this comment..
      otherwise thanks for everything

  • @rafy_works
    @rafy_works Год назад +1

    if i wants to change input value without increment or decrement button but directly from the keyboard typing the quantity amount. how to increment or decrement it by livewire ? Thnks sir

    • @fkwebdev
      @fkwebdev Год назад +1

      @rafy_works I suggest you that don't give your editable input to your users because it may cause a lot of errors for that you've to do a little but complex_validations, so only go them with just increment/decrement button which will limits quantity as you want...
      but however if you want to put input via keyboard then comment me, I'll give you that validation code which will stop user to put negative_value and value greater 10 or as you want....

  • @olegpupkin6892
    @olegpupkin6892 Год назад

    Hello Sir! If user wants to chenge quantity in input value by keyboard, how to increment or decrement it by livewire?

    • @fundaofwebit
      @fundaofwebit  Год назад +1

      You might need to use change() or
      keyUp() or keyPrees() function on that input field and call that livewire function.

  • @waqarmughal4489
    @waqarmughal4489 Год назад

    my increment and decrement not working

  • @farmboy4354
    @farmboy4354 2 года назад

    If it reach max quantity then message comes "only 5 quantity available" after if you try to decrement same message comes "only 5 quantity available" instead of decrement. Can you check once?

    • @fundaofwebit
      @fundaofwebit  2 года назад +2

      Hey,
      There was a small correction: on decrementQuantity() functiion as follows:
      $cartData = Cart::where('id',$cartId)->where('user_id', auth()->user()->id)->first();
      if($cartData)
      {
      if($cartData->quantity > 1){
      $cartData->decrement('quantity');
      $this->dispatchBrowserEvent('message', [
      'text' => 'Quantity Updated',
      'type' => 'success',
      'status' => 200
      ]);
      }else{
      $this->dispatchBrowserEvent('message', [
      'text' => 'Quantity cannot be less than 1',
      'type' => 'success',
      'status' => 200
      ]);
      }
      }else{
      $this->dispatchBrowserEvent('message', [
      'text' => 'Something Went Wrong!',
      'type' => 'error',
      'status' => 404
      ]);
      }

    • @farmboy4354
      @farmboy4354 2 года назад +1

      @@fundaofwebit Thanks for your reply and wonderful tutorials. I added >= now if max quantity is 5 it reach till 6 then message popup that "only 5 quantity available" and then I can't decrement. Even its goes to 0 and negative too.

    • @fundaofwebit
      @fundaofwebit  2 года назад +1

      @@farmboy4354 please, read back the above comment and don't add >= in incrementQuantity().
      keep as it was already as shown in the video.

  • @beticohernandez9536
    @beticohernandez9536 2 года назад

    Interesante hare su proyecto.

  • @yokeshraja1612
    @yokeshraja1612 2 года назад +1

    Sir try to create ecommerce with codeigniter4

  • @onur7485
    @onur7485 Год назад

    6.48