This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.
Hi guys, how are you? I have a question: how can I make backend users have a relation to it self, like a parent_id on users table, then list only models created by the user and its childs, never seen something created by the parent? Cheers.
Are you trying to do something like this?
public function listExtendQuery($query)
{
if (!$this->user->hasAnyAccess(['acme.blog.access_other_posts'])) {
$query->where('user_id', $this->user->id);
}
}
This needs to be placed within your plugins controller e.g Posts.
The user must then have the "access_other_posts" permission defined, otherwise they will be limited to viewing only their own.
Last updated
Thanks for the hint. Probably I will be using something like that.
Now I thinking on a way to make this ownership easy to fetch. Maybe a ownership column that extends parents ownership and adds its id, so user 1 creates user 2, then ownership of user 2 will be 1.2
, them he creates user 3, it will be 1.2.3
. Then queries uses LIKE to fetch: where('ownership', 'LIKE' '%.2.%')
this will query every thing of user 2 e from its children, grandchildren and so on. What do you think?
1-3 of 3