Skip to main content

Black Friday 2025! Only until December 1st: coupon FRIDAY25 for 40% off Yearly/Lifetime membership!

Read more here

Orders Table: Filtering and Ordering

Premium
14 min read

Comments & Discussion

KJ
Karim Jammoul ✓ Link copied!

Hello, I have a question for this function:

	public function deleteSelected(): void
	{
	
			$orders = Order::whereIn('id', $this->selected)->get();

			$orders->each->delete();

			$this->reset('selected');
	}
	

why in this function we loop over the orders then delete them instead of deleting them directly like this:

	Order::whereIn('id', $this->selected)->delete();

As I know that deleting them directly has better performance right? Correct me if I'm wrong please.

Thanks.

PK
Povilas Korop ✓ Link copied!

Because for each of the deleted object, the OBSERVERS would get fired, or other Eloquent events in the future. If we just mass-delete them, yes it's faster but it wouldn't trigger the observers.

A
augusto-dmh ✓ Link copied!

@Povillas Korop isn't there a way to trigger the needed observer events manually iterating over the $orders before mass-deleting them, to avoid N+1 queries for deleting the orders?

A
AlexSteele ✓ Link copied!

I have been experimenting with two aspects of this tutorial, and I Have created a need for something outside the scope but I still want to learn how to do it! We select can select multiple items, and then delete them. I would like to pass an array of names of each item to sweet alert, so that the user can stop the delete if they see something in the displayed list of what is about to be deleted in case they realize that is wrong. I tried a couple of things for this, I was able to adjust the code for a single delete, and pass the name of individual item to sweet alert. I think I need to build an array of these selected names, and pass them to the alert. does this logic exist elsewhere? does this make sense as a feature / concept?

LA
Luis Antonio Parrado ✓ Link copied!

TailwindCSS overrides some styles of Pikaday, you must put pikaday styles after @vite([ ... ])

@vite(['resources/css/app.css', 'resources/js/app.js'])
<link href="https://cdn.jsdelivr.net/npm/pikaday/css/pikaday.css" rel="stylesheet">
ED
Enrique De Jesus Robledo Camacho ✓ Link copied!

What about query strings with the filters?

N
Nerijus ✓ Link copied!

What about them?

IC
Ikaro Campos Laborda ✓ Link copied!

the blade file includes another "svg.sort", in which part of this course is that created?

N
Nerijus ✓ Link copied!

Sort was added in the 11th lesson. Have you skipped it? In that lesson there is a link.

M
muuucho ✓ Link copied!

In order to make delete selected button to be able to be activated when orders are checked, change

<input type="checkbox" value="{{ $order->id }}" wire:model="selected">

to

<input type="checkbox" value="{{ $order->id }}" wire:model.live="selected">

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.