Skip to content

Commit a67e5b9

Browse files
committed
first commit 🔥
1 parent d3d255b commit a67e5b9

File tree

8 files changed

+1917
-17
lines changed

8 files changed

+1917
-17
lines changed

README.md

Lines changed: 231 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
![Users](./arts/screenshot.jpg)
22

3-
# Users Plugin for Laravilt
3+
# Laravilt Users
44

55
[![Latest Stable Version](https://poser.pugx.org/laravilt/users/version.svg)](https://packagist.org/packages/laravilt/users)
66
[![License](https://poser.pugx.org/laravilt/users/license.svg)](https://packagist.org/packages/laravilt/users)
@@ -9,48 +9,240 @@
99
[![PHP Code Styling](https://github.com/laravilt/users/actions/workflows/fix-php-code-styling.yml/badge.svg)](https://github.com/laravilt/users/actions/workflows/fix-php-code-styling.yml)
1010
[![Tests](https://github.com/laravilt/users/actions/workflows/tests.yml/badge.svg)](https://github.com/laravilt/users/actions/workflows/tests.yml)
1111

12-
Users plugin for Laravilt
12+
Complete User and Role management plugin for Laravilt with full RBAC (Role-Based Access Control) system and impersonation support.
1313

14-
## Installation
14+
## Features
15+
16+
### User Management
17+
- **Full CRUD Operations** - Create, read, update, and delete users
18+
- **Avatar Support** - Optional user avatars with fallback to UI Avatars
19+
- **Email Verification** - Track email verification status
20+
- **Role Assignment** - Assign multiple roles to users
21+
- **Search & Filters** - Filter users by role, search by name/email
22+
23+
### Role Management
24+
- **Complete RBAC** - Full Role-Based Access Control system
25+
- **Permission Groups** - Permissions grouped by resource
26+
- **Bulk Selection** - Select all permissions for a resource
27+
- **Guard Support** - Multiple auth guards support
28+
29+
### Impersonation
30+
- **User Impersonation** - Login as any user for debugging/support
31+
- **Session Preservation** - Original session saved during impersonation
32+
- **Banner Notification** - Visual indicator when impersonating
33+
- **Security Controls** - Cannot impersonate self or super admins
34+
35+
### Localization
36+
- **Multi-language** - Full English and Arabic translations
37+
- **RTL Support** - Right-to-left layout support for Arabic
38+
- **Translatable Labels** - All fields, actions, and messages translated
1539

16-
You can install the plugin via composer:
40+
## Requirements
41+
42+
- PHP 8.3+
43+
- Laravel 12+
44+
- Laravilt 1.0+
45+
- Spatie Laravel Permission 6.0+
46+
47+
## Installation
1748

1849
```bash
1950
composer require laravilt/users
2051
```
2152

22-
The package will automatically register its service provider which handles all Laravel-specific functionality (views, migrations, config, etc.).
53+
The service provider is auto-discovered and will register automatically.
54+
55+
### Run Migrations
56+
57+
```bash
58+
php artisan migrate
59+
```
60+
61+
### Install Plugin
62+
63+
```bash
64+
php artisan laravilt:users:install
65+
```
66+
67+
This command will:
68+
- Publish configuration file
69+
- Set up default permissions
70+
- Create default roles (Super Admin, Admin, User)
71+
72+
## Configuration
73+
74+
Publish the configuration file:
75+
76+
```bash
77+
php artisan vendor:publish --tag=laravilt-users-config
78+
```
79+
80+
Configure in `config/laravilt-users.php`:
81+
82+
```php
83+
return [
84+
// Default guard for permissions
85+
'guard_name' => 'web',
86+
87+
// Features (opt-in)
88+
'features' => [
89+
'impersonation' => false, // Enable user impersonation
90+
'avatar' => false, // Enable user avatars
91+
'teams' => false, // Enable team support
92+
'email_verification' => true,
93+
],
94+
95+
// Navigation settings
96+
'navigation' => [
97+
'group' => 'Users & Roles',
98+
'sort' => 1,
99+
],
100+
101+
// Impersonation settings
102+
'impersonation' => [
103+
'redirect_to' => '/admin',
104+
'leave_redirect_to' => '/admin',
105+
],
106+
];
107+
```
23108

24109
## Usage
25110

26-
Register the plugin in your Filament panel provider:
111+
### Register Plugin with Panel
27112

28113
```php
29114
use Laravilt\Users\UsersPlugin;
30115

31-
public function panel(Panel $panel): Panel
116+
class AdminPanelProvider extends PanelProvider
32117
{
33-
return $panel
34-
// ...
35-
->plugin(new UsersPlugin());
118+
public function panel(Panel $panel): Panel
119+
{
120+
return $panel
121+
->plugins([
122+
UsersPlugin::make()
123+
->navigationGroup('Settings')
124+
->navigationSort(10)
125+
->avatar() // Enable avatars
126+
->impersonation(), // Enable impersonation
127+
]);
128+
}
36129
}
37130
```
38-
## Configuration
39131

40-
Publish the config file:
132+
### Plugin Methods
41133

42-
```bash
43-
php artisan vendor:publish --tag="users-config"
134+
```php
135+
UsersPlugin::make()
136+
// Navigation
137+
->navigationGroup('Custom Group') // Set navigation group
138+
->navigationSort(5) // Set navigation order
139+
140+
// Features (opt-in)
141+
->avatar() // Enable avatar feature
142+
->impersonation() // Enable impersonation feature
143+
```
144+
145+
### User Model Setup
146+
147+
Add the required traits to your User model:
148+
149+
```php
150+
use Laravilt\Users\Concerns\HasRolesAndPermissions;
151+
use Laravilt\Users\Concerns\HasAvatar;
152+
153+
class User extends Authenticatable
154+
{
155+
use HasRolesAndPermissions;
156+
use HasAvatar; // Optional, for avatar support
157+
158+
// For impersonation support
159+
public function canImpersonate(): bool
160+
{
161+
return $this->hasRole('super_admin');
162+
}
163+
164+
public function canBeImpersonated(): bool
165+
{
166+
return !$this->hasRole('super_admin');
167+
}
168+
}
44169
```
45170

46-
## Assets
171+
### Setting Up Permissions
47172

48-
Publish the plugin assets:
173+
Run the setup command to create permissions for all resources:
49174

50175
```bash
51-
php artisan vendor:publish --tag="users-assets"
176+
php artisan laravilt:users:setup-permissions
177+
```
178+
179+
This creates permissions like:
180+
- `view_any_user`, `view_user`, `create_user`, `update_user`, `delete_user`
181+
- `view_any_role`, `view_role`, `create_role`, `update_role`, `delete_role`
182+
183+
## Impersonation
184+
185+
### Enable Impersonation
186+
187+
```php
188+
UsersPlugin::make()->impersonation()
189+
```
190+
191+
### Add Middleware
192+
193+
Add the impersonation banner middleware to your panel:
194+
195+
```php
196+
use Laravilt\Users\Http\Middleware\ImpersonationBanner;
197+
198+
$panel->middleware([
199+
ImpersonationBanner::class,
200+
]);
52201
```
53202

203+
### Stop Impersonation
204+
205+
Users can stop impersonation via:
206+
- The banner "Stop Impersonation" button
207+
- Route: `GET /admin/impersonation/leave`
208+
209+
## Resources
210+
211+
### UserResource
212+
213+
Manages users with:
214+
- Avatar (optional)
215+
- Name and Email
216+
- Password management
217+
- Role assignment
218+
- Email verification status
219+
- Created/Updated timestamps
220+
221+
### RoleResource
222+
223+
Manages roles with:
224+
- Role name
225+
- Guard name
226+
- Permission assignment (grouped by resource)
227+
- User count
228+
229+
## Translations
230+
231+
All strings are translatable. Translation files are located in:
232+
- `lang/en/users.php` - English translations
233+
- `lang/ar/users.php` - Arabic translations
234+
235+
## Documentation
236+
237+
Comprehensive documentation is available in the `docs/` directory:
238+
239+
- [Installation](docs/installation.md)
240+
- [Configuration](docs/configuration.md)
241+
- [Users Resource](docs/users.md)
242+
- [Roles Resource](docs/roles.md)
243+
- [Permissions](docs/permissions.md)
244+
- [Impersonation](docs/impersonation.md)
245+
54246
## Testing
55247

56248
```bash
@@ -69,6 +261,28 @@ composer format
69261
composer analyse
70262
```
71263

264+
## Contributing
265+
266+
Please see [CONTRIBUTING.md](.github/CONTRIBUTING.md) for details.
267+
268+
## Security
269+
270+
If you discover any security-related issues, please email info@3x1.io instead of using the issue tracker.
271+
272+
## Changelog
273+
274+
Please see [CHANGELOG.md](CHANGELOG.md) for recent changes.
275+
72276
## License
73277

74278
The MIT License (MIT). Please see [License File](LICENSE.md) for more information.
279+
280+
## Credits
281+
282+
- [Fady Mondy](https://github.com/fadymondy)
283+
- [Spatie](https://github.com/spatie) for Laravel Permission
284+
- [All Contributors](../../contributors)
285+
286+
## Sponsors
287+
288+
Support this project via [GitHub Sponsors](https://github.com/sponsors/fadymondy).

0 commit comments

Comments
 (0)