From edabfb75be1e389cd42a8a769081aab5847463ce Mon Sep 17 00:00:00 2001 From: Milwad Khosravi Date: Wed, 10 Jul 2024 16:51:35 +0330 Subject: [PATCH 01/14] Create LaravelCartStoreItemEvent.php --- src/Events/LaravelCartStoreItemEvent.php | 36 ++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 src/Events/LaravelCartStoreItemEvent.php diff --git a/src/Events/LaravelCartStoreItemEvent.php b/src/Events/LaravelCartStoreItemEvent.php new file mode 100644 index 0000000..46b30b6 --- /dev/null +++ b/src/Events/LaravelCartStoreItemEvent.php @@ -0,0 +1,36 @@ + + */ + public function broadcastOn(): array + { + return [ + new PrivateChannel('channel-name'), + ]; + } +} From 0cd3fa4076a2db953a7939decfdcc37828fa6889 Mon Sep 17 00:00:00 2001 From: Milwad Khosravi Date: Wed, 10 Jul 2024 16:54:30 +0330 Subject: [PATCH 02/14] add event for store item --- src/Models/Cart.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Models/Cart.php b/src/Models/Cart.php index d5f179a..12dd151 100644 --- a/src/Models/Cart.php +++ b/src/Models/Cart.php @@ -2,6 +2,7 @@ namespace Binafy\LaravelCart\Models; +use App\Events\LaravelCartStoreItemEvent; use Binafy\LaravelCart\Cartable; use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Model; @@ -122,6 +123,9 @@ public function storeItem(Model|array $item): static ]); } + // Dispatch event + LaravelCartStoreItemEvent::dispatch(); + return $this; } From 14ec87024341d2fbb47ea7f446d2855dc153e5c5 Mon Sep 17 00:00:00 2001 From: Milwad Khosravi Date: Wed, 10 Jul 2024 16:56:20 +0330 Subject: [PATCH 03/14] add LaravelCartRemoveItemEvent --- src/Events/LaravelCartRemoveItemEvent.php | 36 +++++++++++++++++++++++ src/Models/Cart.php | 6 +++- 2 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 src/Events/LaravelCartRemoveItemEvent.php diff --git a/src/Events/LaravelCartRemoveItemEvent.php b/src/Events/LaravelCartRemoveItemEvent.php new file mode 100644 index 0000000..3f8d8fa --- /dev/null +++ b/src/Events/LaravelCartRemoveItemEvent.php @@ -0,0 +1,36 @@ + + */ + public function broadcastOn(): array + { + return [ + new PrivateChannel('channel-name'), + ]; + } +} diff --git a/src/Models/Cart.php b/src/Models/Cart.php index 12dd151..0964248 100644 --- a/src/Models/Cart.php +++ b/src/Models/Cart.php @@ -4,6 +4,7 @@ use App\Events\LaravelCartStoreItemEvent; use Binafy\LaravelCart\Cartable; +use Binafy\LaravelCart\Events\LaravelCartRemoveItemEvent; use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Model; @@ -123,7 +124,7 @@ public function storeItem(Model|array $item): static ]); } - // Dispatch event + // Dispatch Event LaravelCartStoreItemEvent::dispatch(); return $this; @@ -140,6 +141,9 @@ public function removeItem(Model $item): static $itemToDelete->delete(); } + // Dispatch Event + LaravelCartRemoveItemEvent::dispatch(); + return $this; } From 132a3f8b3ef67c09eb91cf9673d2f97e14cdc299 Mon Sep 17 00:00:00 2001 From: Milwad Khosravi Date: Wed, 10 Jul 2024 16:56:54 +0330 Subject: [PATCH 04/14] add LaravelCartEmptyEvent --- src/Events/LaravelCartEmptyEvent.php | 36 ++++++++++++++++++++++++++++ src/Models/Cart.php | 4 ++++ 2 files changed, 40 insertions(+) create mode 100644 src/Events/LaravelCartEmptyEvent.php diff --git a/src/Events/LaravelCartEmptyEvent.php b/src/Events/LaravelCartEmptyEvent.php new file mode 100644 index 0000000..6fc8240 --- /dev/null +++ b/src/Events/LaravelCartEmptyEvent.php @@ -0,0 +1,36 @@ + + */ + public function broadcastOn(): array + { + return [ + new PrivateChannel('channel-name'), + ]; + } +} diff --git a/src/Models/Cart.php b/src/Models/Cart.php index 0964248..f00649f 100644 --- a/src/Models/Cart.php +++ b/src/Models/Cart.php @@ -4,6 +4,7 @@ use App\Events\LaravelCartStoreItemEvent; use Binafy\LaravelCart\Cartable; +use Binafy\LaravelCart\Events\LaravelCartEmptyEvent; use Binafy\LaravelCart\Events\LaravelCartRemoveItemEvent; use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Model; @@ -154,6 +155,9 @@ public function emptyCart(): static { $this->items()->delete(); + // Dispatch Event + LaravelCartEmptyEvent::dispatch(); + return $this; } From eb2c3fbb96ddb8117710da86e30af92f7c529c73 Mon Sep 17 00:00:00 2001 From: Milwad Khosravi Date: Wed, 10 Jul 2024 16:57:31 +0330 Subject: [PATCH 05/14] add LaravelCartIncreaseQuantityEvent --- .../LaravelCartIncreaseQuantityEvent.php | 36 +++++++++++++++++++ src/Models/Cart.php | 4 +++ 2 files changed, 40 insertions(+) create mode 100644 src/Events/LaravelCartIncreaseQuantityEvent.php diff --git a/src/Events/LaravelCartIncreaseQuantityEvent.php b/src/Events/LaravelCartIncreaseQuantityEvent.php new file mode 100644 index 0000000..1dc6cfc --- /dev/null +++ b/src/Events/LaravelCartIncreaseQuantityEvent.php @@ -0,0 +1,36 @@ + + */ + public function broadcastOn(): array + { + return [ + new PrivateChannel('channel-name'), + ]; + } +} diff --git a/src/Models/Cart.php b/src/Models/Cart.php index f00649f..773a96b 100644 --- a/src/Models/Cart.php +++ b/src/Models/Cart.php @@ -5,6 +5,7 @@ use App\Events\LaravelCartStoreItemEvent; use Binafy\LaravelCart\Cartable; use Binafy\LaravelCart\Events\LaravelCartEmptyEvent; +use Binafy\LaravelCart\Events\LaravelCartIncreaseQuantityEvent; use Binafy\LaravelCart\Events\LaravelCartRemoveItemEvent; use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Model; @@ -173,6 +174,9 @@ public function increaseQuantity(Model $item, int $quantity = 1): static $item->increment('quantity', $quantity); + // Dispatch Event + LaravelCartIncreaseQuantityEvent::dispatch($item); + return $this; } From 78480089f3c806a20a248301cf082d5d649d96da Mon Sep 17 00:00:00 2001 From: Milwad Khosravi Date: Wed, 10 Jul 2024 16:58:00 +0330 Subject: [PATCH 06/14] add LaravelCartDecreaseQuantityEvent --- .../LaravelCartDecreaseQuantityEvent.php | 36 +++++++++++++++++++ src/Models/Cart.php | 4 +++ 2 files changed, 40 insertions(+) create mode 100644 src/Events/LaravelCartDecreaseQuantityEvent.php diff --git a/src/Events/LaravelCartDecreaseQuantityEvent.php b/src/Events/LaravelCartDecreaseQuantityEvent.php new file mode 100644 index 0000000..aa7b9ab --- /dev/null +++ b/src/Events/LaravelCartDecreaseQuantityEvent.php @@ -0,0 +1,36 @@ + + */ + public function broadcastOn(): array + { + return [ + new PrivateChannel('channel-name'), + ]; + } +} diff --git a/src/Models/Cart.php b/src/Models/Cart.php index 773a96b..ae4653e 100644 --- a/src/Models/Cart.php +++ b/src/Models/Cart.php @@ -4,6 +4,7 @@ use App\Events\LaravelCartStoreItemEvent; use Binafy\LaravelCart\Cartable; +use Binafy\LaravelCart\Events\LaravelCartDecreaseQuantityEvent; use Binafy\LaravelCart\Events\LaravelCartEmptyEvent; use Binafy\LaravelCart\Events\LaravelCartIncreaseQuantityEvent; use Binafy\LaravelCart\Events\LaravelCartRemoveItemEvent; @@ -192,6 +193,9 @@ public function decreaseQuantity(Model $item, int $quantity = 1): static $item->decrement('quantity', $quantity); + // Dispatch Event + LaravelCartDecreaseQuantityEvent::dispatch($item); + return $this; } } From a7406a11177fea3cf7235d79d82495d5573fbf94 Mon Sep 17 00:00:00 2001 From: Milwad Khosravi Date: Wed, 10 Jul 2024 17:02:10 +0330 Subject: [PATCH 07/14] wip --- src/Events/LaravelCartStoreItemEvent.php | 2 +- src/Models/Cart.php | 2 +- tests/Feature/Models/CartDeleteTest.php | 11 ++++++++++- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/Events/LaravelCartStoreItemEvent.php b/src/Events/LaravelCartStoreItemEvent.php index 46b30b6..79ebf62 100644 --- a/src/Events/LaravelCartStoreItemEvent.php +++ b/src/Events/LaravelCartStoreItemEvent.php @@ -1,6 +1,6 @@ create(['name' => 'Milwad', 'email' => 'milwad.dev@gmail.comd']); $product1 = Product::query()->create(['title' => 'Product 1']); $product2 = Product::query()->create(['title' => 'Product 2']); @@ -54,6 +59,10 @@ $cart->removeItem($product1); assertDatabaseCount('cart_items', 2); + + // Event Assertions + Event::assertDispatched(LaravelCartStoreItemEvent::class); + Event::assertDispatched(LaravelCartRemoveItemEvent::class); }); test('can empty the cart', function () { From 5fed1b25951c737d61077f7e2eb920201fc25311 Mon Sep 17 00:00:00 2001 From: Milwad Khosravi Date: Wed, 10 Jul 2024 17:02:39 +0330 Subject: [PATCH 08/14] Update CartDeleteTest.php --- tests/Feature/Models/CartDeleteTest.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/Feature/Models/CartDeleteTest.php b/tests/Feature/Models/CartDeleteTest.php index 8b0beff..3220a7d 100644 --- a/tests/Feature/Models/CartDeleteTest.php +++ b/tests/Feature/Models/CartDeleteTest.php @@ -1,5 +1,6 @@ create(['name' => 'Milwad', 'email' => 'milwad.dev@gmail.comd']); $product1 = Product::query()->create(['title' => 'Product 1']); $product2 = Product::query()->create(['title' => 'Product 2']); @@ -100,4 +103,8 @@ // Remove all items from cart $cart->emptyCart(); assertDatabaseCount('cart_items', 0); + + // Event Assertions + Event::assertDispatched(LaravelCartStoreItemEvent::class); + Event::assertDispatched(LaravelCartEmptyEvent::class); }); From 34814e46e52a95472c6d4be63eb281f8ca8e0a6a Mon Sep 17 00:00:00 2001 From: Milwad Date: Thu, 18 Jul 2024 13:11:54 +0330 Subject: [PATCH 09/14] improve CartStoreTest --- src/Models/Cart.php | 3 +++ tests/Feature/Models/CartStoreTest.php | 21 +++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/src/Models/Cart.php b/src/Models/Cart.php index 97e804f..513901c 100644 --- a/src/Models/Cart.php +++ b/src/Models/Cart.php @@ -74,6 +74,9 @@ public function scopeFirstOrCreateWithStoreItems( $cart->items()->save($cartItem); + // Dispatch Event + LaravelCartStoreItemEvent::dispatch(); + return $query; } diff --git a/tests/Feature/Models/CartStoreTest.php b/tests/Feature/Models/CartStoreTest.php index a363ef9..821f241 100644 --- a/tests/Feature/Models/CartStoreTest.php +++ b/tests/Feature/Models/CartStoreTest.php @@ -1,5 +1,6 @@ create(['name' => 'Milwad', 'email' => 'milwad.dev@gmail.comd']); $product = Product::query()->create(['title' => 'Product 1']); @@ -92,9 +95,14 @@ 'itemable_type' => $product::class, 'quantity' => 1, ]); + + // Event Assertion + Event::assertDispatched(LaravelCartStoreItemEvent::class); }); test('can store product in cart with firstOrCreateWithItems scope when user sign-in', function () { + Event::fake(); + $user = User::query()->create(['name' => 'Milwad', 'email' => 'milwad.dev@gmail.comd']); $product = Product::query()->create(['title' => 'Product 1']); @@ -110,9 +118,14 @@ 'itemable_type' => $product::class, 'quantity' => 1, ]); + + // Event Assertion + Event::assertDispatched(LaravelCartStoreItemEvent::class); }); test('can store multiple products in cart', function () { + Event::fake(); + $user = User::query()->create(['name' => 'Milwad', 'email' => 'milwad.dev@gmail.comd']); $product1 = Product::query()->create(['title' => 'Product 1']); $product2 = Product::query()->create(['title' => 'Product 1']); @@ -144,6 +157,9 @@ 'itemable_type' => $product1::class, 'quantity' => 2, ]); + + // Event Assertion + Event::assertDispatchedTimes(LaravelCartStoreItemEvent::class, 3); }); test('get correct price with calculated quantity', function () { @@ -184,6 +200,8 @@ }); test('can not store product in cart when item is not instance of cartable', function () { + Event::fake(); + $user = User::query()->create(['name' => 'Milwad', 'email' => 'milwad.dev@gmail.comd']); $user2 = User::query()->create(['name' => 'Binafy', 'email' => 'binafy23@gmail.comd']); @@ -202,4 +220,7 @@ 'itemable_type' => $user2::class, 'quantity' => 2, ]); + + // Event Assertion + Event::assertNotDispatched(LaravelCartStoreItemEvent::class); })->expectExceptionMessage('The item must be an instance of Cartable'); From a8396ad6f8a024a8bc746e59467cf7fbece03d4c Mon Sep 17 00:00:00 2001 From: Milwad Date: Thu, 18 Jul 2024 13:14:11 +0330 Subject: [PATCH 10/14] improve CartUpdateQuantityTest --- .../Feature/Models/CartUpdateQuantityTest.php | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/tests/Feature/Models/CartUpdateQuantityTest.php b/tests/Feature/Models/CartUpdateQuantityTest.php index a4a8b14..f18912b 100644 --- a/tests/Feature/Models/CartUpdateQuantityTest.php +++ b/tests/Feature/Models/CartUpdateQuantityTest.php @@ -1,5 +1,8 @@ create(['name' => 'Milwad', 'email' => 'milwad.dev@gmail.comd']); $product = Product::query()->create(['title' => 'Product 1']); @@ -35,9 +40,14 @@ $cart->increaseQuantity($product, 2); assertDatabaseHas('cart_items', ['quantity' => 3]); + + // Event Assertion + Event::assertDispatched(LaravelCartIncreaseQuantityEvent::class); }); test('can decrease quantity of the item in cart', function () { + Event::fake(); + $user = User::query()->create(['name' => 'Milwad', 'email' => 'milwad.dev@gmail.comd']); $product = Product::query()->create(['title' => 'Product 1']); @@ -59,9 +69,14 @@ $cart->decreaseQuantity($product, 2); assertDatabaseHas('cart_items', ['quantity' => 1]); + + // Event Assertion + Event::assertDispatched(LaravelCartDecreaseQuantityEvent::class); }); test('can not increase quantity of the item in cart when item not found', function () { + Event::fake(); + $user = User::query()->create(['name' => 'Milwad', 'email' => 'milwad.dev@gmail.comd']); $product1 = Product::query()->create(['title' => 'Product 1']); @@ -84,9 +99,14 @@ $cart->increaseQuantity($product2, 2); assertDatabaseHas('cart_items', ['quantity' => 1]); + + // Event Assertion + Event::assertNotDispatched(LaravelCartIncreaseQuantityEvent::class); })->expectExceptionMessage('The item not found'); test('can not decrease quantity of the item in cart when item not found', function () { + Event::fake(); + $user = User::query()->create(['name' => 'Milwad', 'email' => 'milwad.dev@gmail.comd']); $product1 = Product::query()->create(['title' => 'Product 1']); @@ -109,4 +129,7 @@ $cart->decreaseQuantity($product2, 2); assertDatabaseHas('cart_items', ['quantity' => 3]); + + // Event Assertion + Event::assertNotDispatched(LaravelCartDecreaseQuantityEvent::class); })->expectExceptionMessage('The item not found'); From 857b6a84da26ea6c5ed5f350b3d11bbf5591e4f2 Mon Sep 17 00:00:00 2001 From: Milwad Date: Thu, 18 Jul 2024 13:16:39 +0330 Subject: [PATCH 11/14] remove broadcast method from events --- src/Events/LaravelCartDecreaseQuantityEvent.php | 12 ------------ src/Events/LaravelCartEmptyEvent.php | 12 ------------ src/Events/LaravelCartIncreaseQuantityEvent.php | 12 ------------ src/Events/LaravelCartRemoveItemEvent.php | 12 ------------ src/Events/LaravelCartStoreItemEvent.php | 12 ------------ 5 files changed, 60 deletions(-) diff --git a/src/Events/LaravelCartDecreaseQuantityEvent.php b/src/Events/LaravelCartDecreaseQuantityEvent.php index aa7b9ab..8394136 100644 --- a/src/Events/LaravelCartDecreaseQuantityEvent.php +++ b/src/Events/LaravelCartDecreaseQuantityEvent.php @@ -21,16 +21,4 @@ public function __construct() { // } - - /** - * Get the channels the event should broadcast on. - * - * @return array - */ - public function broadcastOn(): array - { - return [ - new PrivateChannel('channel-name'), - ]; - } } diff --git a/src/Events/LaravelCartEmptyEvent.php b/src/Events/LaravelCartEmptyEvent.php index 6fc8240..a6e50f0 100644 --- a/src/Events/LaravelCartEmptyEvent.php +++ b/src/Events/LaravelCartEmptyEvent.php @@ -21,16 +21,4 @@ public function __construct() { // } - - /** - * Get the channels the event should broadcast on. - * - * @return array - */ - public function broadcastOn(): array - { - return [ - new PrivateChannel('channel-name'), - ]; - } } diff --git a/src/Events/LaravelCartIncreaseQuantityEvent.php b/src/Events/LaravelCartIncreaseQuantityEvent.php index 1dc6cfc..433ca74 100644 --- a/src/Events/LaravelCartIncreaseQuantityEvent.php +++ b/src/Events/LaravelCartIncreaseQuantityEvent.php @@ -21,16 +21,4 @@ public function __construct() { // } - - /** - * Get the channels the event should broadcast on. - * - * @return array - */ - public function broadcastOn(): array - { - return [ - new PrivateChannel('channel-name'), - ]; - } } diff --git a/src/Events/LaravelCartRemoveItemEvent.php b/src/Events/LaravelCartRemoveItemEvent.php index 3f8d8fa..3a31f20 100644 --- a/src/Events/LaravelCartRemoveItemEvent.php +++ b/src/Events/LaravelCartRemoveItemEvent.php @@ -21,16 +21,4 @@ public function __construct() { // } - - /** - * Get the channels the event should broadcast on. - * - * @return array - */ - public function broadcastOn(): array - { - return [ - new PrivateChannel('channel-name'), - ]; - } } diff --git a/src/Events/LaravelCartStoreItemEvent.php b/src/Events/LaravelCartStoreItemEvent.php index 79ebf62..f2198fb 100644 --- a/src/Events/LaravelCartStoreItemEvent.php +++ b/src/Events/LaravelCartStoreItemEvent.php @@ -21,16 +21,4 @@ public function __construct() { // } - - /** - * Get the channels the event should broadcast on. - * - * @return array - */ - public function broadcastOn(): array - { - return [ - new PrivateChannel('channel-name'), - ]; - } } From 3f06c792844664a113908908f3638a55b1467929 Mon Sep 17 00:00:00 2001 From: Milwad Date: Thu, 18 Jul 2024 13:29:52 +0330 Subject: [PATCH 12/14] pint --- src/Events/LaravelCartDecreaseQuantityEvent.php | 4 ---- src/Events/LaravelCartEmptyEvent.php | 4 ---- src/Events/LaravelCartIncreaseQuantityEvent.php | 4 ---- src/Events/LaravelCartRemoveItemEvent.php | 4 ---- src/Events/LaravelCartStoreItemEvent.php | 4 ---- src/Models/Cart.php | 2 +- tests/Feature/Models/CartUpdateQuantityTest.php | 1 - 7 files changed, 1 insertion(+), 22 deletions(-) diff --git a/src/Events/LaravelCartDecreaseQuantityEvent.php b/src/Events/LaravelCartDecreaseQuantityEvent.php index 8394136..0a585b7 100644 --- a/src/Events/LaravelCartDecreaseQuantityEvent.php +++ b/src/Events/LaravelCartDecreaseQuantityEvent.php @@ -2,11 +2,7 @@ namespace Binafy\LaravelCart\Events; -use Illuminate\Broadcasting\Channel; use Illuminate\Broadcasting\InteractsWithSockets; -use Illuminate\Broadcasting\PresenceChannel; -use Illuminate\Broadcasting\PrivateChannel; -use Illuminate\Contracts\Broadcasting\ShouldBroadcast; use Illuminate\Foundation\Events\Dispatchable; use Illuminate\Queue\SerializesModels; diff --git a/src/Events/LaravelCartEmptyEvent.php b/src/Events/LaravelCartEmptyEvent.php index a6e50f0..52ad63a 100644 --- a/src/Events/LaravelCartEmptyEvent.php +++ b/src/Events/LaravelCartEmptyEvent.php @@ -2,11 +2,7 @@ namespace Binafy\LaravelCart\Events; -use Illuminate\Broadcasting\Channel; use Illuminate\Broadcasting\InteractsWithSockets; -use Illuminate\Broadcasting\PresenceChannel; -use Illuminate\Broadcasting\PrivateChannel; -use Illuminate\Contracts\Broadcasting\ShouldBroadcast; use Illuminate\Foundation\Events\Dispatchable; use Illuminate\Queue\SerializesModels; diff --git a/src/Events/LaravelCartIncreaseQuantityEvent.php b/src/Events/LaravelCartIncreaseQuantityEvent.php index 433ca74..3088eac 100644 --- a/src/Events/LaravelCartIncreaseQuantityEvent.php +++ b/src/Events/LaravelCartIncreaseQuantityEvent.php @@ -2,11 +2,7 @@ namespace Binafy\LaravelCart\Events; -use Illuminate\Broadcasting\Channel; use Illuminate\Broadcasting\InteractsWithSockets; -use Illuminate\Broadcasting\PresenceChannel; -use Illuminate\Broadcasting\PrivateChannel; -use Illuminate\Contracts\Broadcasting\ShouldBroadcast; use Illuminate\Foundation\Events\Dispatchable; use Illuminate\Queue\SerializesModels; diff --git a/src/Events/LaravelCartRemoveItemEvent.php b/src/Events/LaravelCartRemoveItemEvent.php index 3a31f20..97d00e9 100644 --- a/src/Events/LaravelCartRemoveItemEvent.php +++ b/src/Events/LaravelCartRemoveItemEvent.php @@ -2,11 +2,7 @@ namespace Binafy\LaravelCart\Events; -use Illuminate\Broadcasting\Channel; use Illuminate\Broadcasting\InteractsWithSockets; -use Illuminate\Broadcasting\PresenceChannel; -use Illuminate\Broadcasting\PrivateChannel; -use Illuminate\Contracts\Broadcasting\ShouldBroadcast; use Illuminate\Foundation\Events\Dispatchable; use Illuminate\Queue\SerializesModels; diff --git a/src/Events/LaravelCartStoreItemEvent.php b/src/Events/LaravelCartStoreItemEvent.php index f2198fb..fd344f3 100644 --- a/src/Events/LaravelCartStoreItemEvent.php +++ b/src/Events/LaravelCartStoreItemEvent.php @@ -2,11 +2,7 @@ namespace Binafy\LaravelCart\Events; -use Illuminate\Broadcasting\Channel; use Illuminate\Broadcasting\InteractsWithSockets; -use Illuminate\Broadcasting\PresenceChannel; -use Illuminate\Broadcasting\PrivateChannel; -use Illuminate\Contracts\Broadcasting\ShouldBroadcast; use Illuminate\Foundation\Events\Dispatchable; use Illuminate\Queue\SerializesModels; diff --git a/src/Models/Cart.php b/src/Models/Cart.php index 513901c..8ee6a0d 100644 --- a/src/Models/Cart.php +++ b/src/Models/Cart.php @@ -2,12 +2,12 @@ namespace Binafy\LaravelCart\Models; -use Binafy\LaravelCart\Events\LaravelCartStoreItemEvent; use Binafy\LaravelCart\Cartable; use Binafy\LaravelCart\Events\LaravelCartDecreaseQuantityEvent; use Binafy\LaravelCart\Events\LaravelCartEmptyEvent; use Binafy\LaravelCart\Events\LaravelCartIncreaseQuantityEvent; use Binafy\LaravelCart\Events\LaravelCartRemoveItemEvent; +use Binafy\LaravelCart\Events\LaravelCartStoreItemEvent; use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Model; diff --git a/tests/Feature/Models/CartUpdateQuantityTest.php b/tests/Feature/Models/CartUpdateQuantityTest.php index f18912b..70de3cc 100644 --- a/tests/Feature/Models/CartUpdateQuantityTest.php +++ b/tests/Feature/Models/CartUpdateQuantityTest.php @@ -2,7 +2,6 @@ use Binafy\LaravelCart\Events\LaravelCartDecreaseQuantityEvent; use Binafy\LaravelCart\Events\LaravelCartIncreaseQuantityEvent; -use Binafy\LaravelCart\Events\LaravelCartStoreItemEvent; use Binafy\LaravelCart\Models\Cart; use Binafy\LaravelCart\Models\CartItem; use Illuminate\Foundation\Testing\RefreshDatabase; From 1d90710470ded2042c6c13774eff133a6bc103f1 Mon Sep 17 00:00:00 2001 From: Milwad Date: Thu, 18 Jul 2024 13:35:33 +0330 Subject: [PATCH 13/14] Update README.md --- README.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/README.md b/README.md index 76037bb..0825360 100644 --- a/README.md +++ b/README.md @@ -27,6 +27,7 @@ - [Delete All Items From Cart](#delete-all-items-from-cart) - [Increase Quantity](#increase-quantity) - [Decrease Quantity](#decrease-quantity) + - [Available Events](#available-events) - [Contributors](#contributors) - [Security](#security) - [Changelog](#changelog) @@ -312,6 +313,19 @@ If you may to decrease the quantity of item in cart, you can use `decreaseQuanti $cart->decreaseQuantity(item: $item, quantity: 2); // By default quantity is 1 ``` + +### Available Events + +The `Laravel Cart` have some events that you can listen to these event and doing something: + +| Events | Description | +|----------------------------------|-------------| +| LaravelCartStoreItemEvent | Title | +| LaravelCartRemoveItemEvent | Text | +| LaravelCartEmptyEvent | Text | +| LaravelCartIncreaseQuantityEvent | Text | +| LaravelCartDecreaseQuantityEvent | Text | + ## Contributors From b956ea6c5dd17896f9a76ecd8a17e22999616690 Mon Sep 17 00:00:00 2001 From: Milwad Date: Thu, 18 Jul 2024 13:38:16 +0330 Subject: [PATCH 14/14] Update README.md --- README.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 0825360..f5384ff 100644 --- a/README.md +++ b/README.md @@ -318,13 +318,13 @@ $cart->decreaseQuantity(item: $item, quantity: 2); // By default quantity is 1 The `Laravel Cart` have some events that you can listen to these event and doing something: -| Events | Description | -|----------------------------------|-------------| -| LaravelCartStoreItemEvent | Title | -| LaravelCartRemoveItemEvent | Text | -| LaravelCartEmptyEvent | Text | -| LaravelCartIncreaseQuantityEvent | Text | -| LaravelCartDecreaseQuantityEvent | Text | +| Events | Description | +|------------------------------------|------------------------------------------------------------------| +| `LaravelCartStoreItemEvent` | When you store an item in cart, this event fired | +| `LaravelCartRemoveItemEvent` | When you remove an item from cart, this event fired | +| `LaravelCartEmptyEvent` | When you remove all items from cart, this event fired | +| `LaravelCartIncreaseQuantityEvent` | When you increase the quantity of item in cart, this event fired | +| `LaravelCartDecreaseQuantityEvent` | When you decrease the quantity of item in cart, this event fired | ## Contributors