Comments (9)
Add the constraint to the query:
$users = User::find($id)->descendants()->whereDepth('<', 10)->where('active', 1)->get();
from laravel-adjacency-list.
Thank you @staudenmeir , is it possible to group the depth/level?
Depth/Level 1
- John
Depth/Level 2
- Jane
from laravel-adjacency-list.
Do you mean something like $users->groupBy('depth')
?
from laravel-adjacency-list.
yes @staudenmeir , and I want to loop the depth to it will show like
Depth/Level 1
- John
Depth/Level 2
- Jane
from laravel-adjacency-list.
Have you tried looping over the result of $users->groupBy('depth')
?
from laravel-adjacency-list.
I tried but it's showing Property [depth] does not exist on this collection instance.
$users = User::find($id)->descendants()->whereDepth('<', 10)->where('active',1)->get();
@foreach($users->groupBy('depth') as $level)
{{ $level->depth }}
@endforeach
from laravel-adjacency-list.
Take a look at dd($users->groupBy('depth'));
and the documentation.
from laravel-adjacency-list.
@staudenmeir thank you.
from laravel-adjacency-list.
@staudenmeir I've solved it 👍 thank you. I will close this issue now.
from laravel-adjacency-list.
Related Issues (20)
- How can I include rootAncestor path with the model itself? HOT 3
- ModelName::tree()->get() gives "SQLSTATE[HY093]: Invalid parameter number" HOT 4
- Get descendants based on children existence HOT 2
- Parent has many Children trees HOT 3
- Problem with custom path HOT 2
- Has many of a model where ancestors may belong to it. HOT 9
- Aggregate Purchases for Parent Users HOT 8
- limit hasManyOfDescendants depth HOT 2
- Larastan types `ancestorsAndSelf` property as `Model|null` instead of Collection HOT 4
- escapeWhenCastingToString ? HOT 1
- Path and custom paths are not consistent HOT 3
- toTree on graph ancestors not working properly
- Can't add constraints to initial query and recursive query of a graph relation HOT 6
- [Question] Return tree (children recursively) with relation HOT 2
- SQLSTATE[42S02]: Base table or view not found: 1051 Unknown table 'topics' on withCount HOT 7
- Organization filter in policy HOT 1
- How to recursively replicate models HOT 5
- can we use recurcive relationship for BelongsToManyJson relations? HOT 3
- Internal error: Internal error: Method newEloquentBuilder() was not found in reflection of class Staudenmeir\LaravelAdjacencyList\Eloquent\Relations\Descendants. HOT 17
- IDE-helper too many comments HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from laravel-adjacency-list.