How to access user groups from a laravel controller?
Forum rules
Always add your Laravel, Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
Always add your Laravel, Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
-
- Posts: 26
- Joined: 16 Oct 2023, 15:05
How to access user groups from a laravel controller?
I am trying to get user groups from Laravel Controller. Is there any sample code that I can refer to?
Re: How to access user groups from a laravel controller?
What do you want them for?
For access control use the group codes like this (https://laravel.com/docs/10.x/authoriza ... er-helpers):
That works because of these lines: https://github.com/aimeos/aimeos-larave ... entication
The group IDs are available in the context:
You can get the user group items like this:
Alternatively using the customer frontend controller:
For access control use the group codes like this (https://laravel.com/docs/10.x/authoriza ... er-helpers):
Code: Select all
$this->authorize( 'admin', [get_class($this), ['admin', 'editor']] );
The group IDs are available in the context:
Code: Select all
$groupIds = app( 'aimeos.context' )->get()->groups()
Code: Select all
$user = Aimeos\Shop\Facades\Customer::uses( ['customer/group'] )->get()
$groups = $user->getRefItems( 'customer/group' );
Code: Select all
$user = \Aimeos\Controller\Frontend::create( app( 'aimeos.context' )->get(), 'customer' )
->uses( ['customer/group'] )->get()
$groups = $user->getRefItems( 'customer/group' );
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos,
give us a star
If you like Aimeos,
![Image](https://aimeos.org/fileadmin/aimeos.org/icons/star.png)
-
- Posts: 26
- Joined: 16 Oct 2023, 15:05
-
- Posts: 26
- Joined: 16 Oct 2023, 15:05
Re: How to access user groups from a laravel controller?
Tried the code today and groups was returning empty. This is the printed $user variable. Any missing configuration?
- Attachments
-
- Image 26.png (22.67 KiB) Viewed 20294 times
Re: How to access user groups from a laravel controller?
Which of the alternatives did you use?
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos,
give us a star
If you like Aimeos,
![Image](https://aimeos.org/fileadmin/aimeos.org/icons/star.png)
-
- Posts: 26
- Joined: 16 Oct 2023, 15:05
Re: How to access user groups from a laravel controller?
May I know what is meant by alternatives ?
Re: How to access user groups from a laravel controller?
Which of those lines did you use?
aimeos wrote: ↑18 Oct 2023, 07:10 The group IDs are available in the context:You can get the user group items like this:Code: Select all
$groupIds = app( 'aimeos.context' )->get()->groups()
Alternatively using the customer frontend controller:Code: Select all
$user = Aimeos\Shop\Facades\Customer::uses( ['customer/group'] )->get() $groups = $user->getRefItems( 'customer/group' );
Code: Select all
$user = \Aimeos\Controller\Frontend::create( app( 'aimeos.context' )->get(), 'customer' ) ->uses( ['customer/group'] )->get() $groups = $user->getRefItems( 'customer/group' );
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos,
give us a star
If you like Aimeos,
![Image](https://aimeos.org/fileadmin/aimeos.org/icons/star.png)
-
- Posts: 26
- Joined: 16 Oct 2023, 15:05
Re: How to access user groups from a laravel controller?
I used this one
Code: Select all
$user = \Aimeos\Controller\Frontend::create( app( 'aimeos.context' )->get(), 'customer' )
->uses( ['customer/group'] )->get()
$groups = $user->getRefItems( 'customer/group' );
Re: How to access user groups from a laravel controller?
Remember that you must be logged in to retrieve the user and his groups.
According to your screenshot, this isn't the case.
According to your screenshot, this isn't the case.
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos,
give us a star
If you like Aimeos,
![Image](https://aimeos.org/fileadmin/aimeos.org/icons/star.png)