Laravel Tip - Format Multilevel Categories With Single Query

preview_player
Показать описание
In this Laravel tip video, we will have a look at how to format a multi-level categories tree using only one query in Laravel.

=== Important Links ===

Fonts, extensions I use, and Support Laratips links:

=== Offer ===

Get up to Free Hosting by using code "LARATIPS" and you get $15 as credit which can last almost a month.

Cloudways offers peace of mind and flexibility so you can focus on growing your business and reaching new milestones instead of dealing with server management. With Cloudways, you get an optimized stack, managed servers, backups, staging environment, integrated Git, pre-configured, Composer, 24/7 support, and the choice of five cloud providers: AWS, DigitalOcean, Linode, Google Cloud, and Vultr

====================== Support ======================

If you want me to continue making this kind of video for free on YouTube, then you can support the channel

eSewa ID: 9843632084

===

GitHub repo:

Format Multilevel Categories Using Only Has Many Relationship (Previous Video)

Social Media Links:

Let's be friends

Follow On Facebook

Tech stack:
Laravel
PHP

#laravel #php #laraveltip #laratips
Рекомендации по теме
Комментарии
Автор

Just discovered this channel. What a gift!

eatsfunk
Автор

Fantastic. That's what i'm looking for days. Thank you/

awaidus
Автор

Thanks a lot from Bangladesh for this more essential video❤️

md.anwarhossain
Автор

If we are in a child catagory. We like to go back in parent category then how we can show ? Like i am in 4 number sub catagory.. the how i can show 4》3》2》1》0 ?

mahbubhasan
Автор

Amazing video bro ty for share the knowledge .♥

Zdlk
Автор

Amazing...🔥🔥
Can you make one more video for shown this categories in front end side with pagination with orderBy name in each categories and their subcategory of available
A
AA
AAA
AAAA
AAB
AB
AC
B
C
D....
Like that...
I am able to show this like tree structure without pagination, but how to do with pagination?

meetvaghasia
Автор

thank you very much ... could you plz make video for showing the tree in blade :)

programar-tktb
Автор

This is very good but i have one problem in this way, like orderBy or paginate is not working in this way, if you have another way to implement paginate.

irfanakram
Автор

Please share the blade function/ CRUD example.

debjit
Автор

Thank you bro, . great tutorial. can on easily perform crud on these category?

opahprincewill
Автор

You can use nested with on your relation like this:

public function children(): HasMany
{
return $this->hasMany(Category::class, 'parent_id', 'id')->with('children');
}

public static function getThree(): array
{
return
}

This solution avoid the n+1 query problem. If you have 3 nested, only 3 sql requests...

ColantAlan
Автор

Hi, can you show the blade part of this query to show how it will be working on a navigation of a website?

davidson
Автор

Please sir, how can we get the count of each category items with their subcategories. Anyone please

donatusbrainokwe
Автор

Can you make some gist or something it will be much useful then write from the video ;)

stojankukrika
Автор

when we have millions of categories, it will be long processing. need more efficient algorithm.
maybe add "path" column

MetriWahyudi
Автор

How to add products_count foreach category level

cdma
Автор

can make crud example sir please this i need

robyortega
Автор

how to get all ids of children using find method not get ? example: $cat = Category::Find( $id ); and then get all children ids of this category

turkialharbi
Автор

I'm so used to seeing crap tech tutorials on YouTube by people with Asian accents that I almost immediately closed this. I'm glad I didn't. I was being prejudice without realizing, and for that I apologize.

tekelupharsin
Автор

Why you dont use eloquent relation hasMany and repeat the relation instead of function recursive.
Try:
public function children()
{
return $this→hasMany(Category::class, function($query){
return $query-›with("children");
}])
}

Thats it! Few lines

mohamadcheaib