Support the ongoing development of Laravel.io →
posted 5 years ago
Eloquent
Last updated 2 years ago.
0

Hi,

I found a solution but is not very elegant :

public function hasdata(){
$pages = $this->pages()->get()->isEmpty();
$episodes = $this->episodes()->get()->isEmpty();
$events = $this->events()->get()->isEmpty();
$teasers = $this->teasers()->get()->isEmpty();
$articles = $this->articles()->get()->isEmpty();
$flag = [$pages, $episodes, $events, $teasers, $articles];
if(in_array(false, $flag)){return true;}
return false;
}
0

The solution provided above really works. Thanks!

laravel.io member write my essay today

0

The quickest approach is an existence query:

select NOT EXISTS (select username from a where username = {$username}) AND NOT EXISTS (select username from b where username = {$username}) AND NOT EXISTS (select username from c where username = {$username});

If your username column is marked as Unique in each table, this should be the most efficient query you will be able to make to perform this operation, and this will outperform a normalized username table in terms of memory usage and, well, virtually any other query that cares about username and another column, as there are no excessive joins. If you've ever been called on to speed up an organization's database, I can assure you that over-normalization is a nightmare. In regards to the advice you've received on normalization in this thread, be wary. It's great for limiting space, or limiting the number of places you have to update data, but you have to weigh that against the maintenance and speed overhead. Take the advice on how to start off an informative essay given to you on this page with a grain of salt.

Get used to running a query analyzer on your queries, if for no other reason than to get in the habit of learning the ramifications of choices when writing queries -- at least until you get your sea legs.

0

Hi Everyone,

I think to create a view table and call it on ever updated, and maybe even put the whole view table on redis if available, so you will be able to read the table much faster https://blog.tekz.io/laravel-eloquent-how-to-effectively-manage-sql-views/

It is just a idea

0

Sign in to participate in this thread!

Eventy

Your banner here too?

visualight visualight Joined 30 Dec 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.