Admin Livewire Components
This page documents the Livewire components used in the LaraCMS admin panel for managing users, blog posts, and other administrative tasks.UserList
Namespace:App\Livewire\Admin\UserList
Location: app/Livewire/Admin/UserList.php:9
Displays a paginated, searchable, and sortable list of users with delete functionality.
Properties
| Property | Type | Default | Description |
|---|---|---|---|
$search | string | '' | Search query for filtering users by name or email |
$sortField | string | 'name' | Field to sort by |
$sortDirection | string | 'asc' | Sort direction (asc/desc) |
$showDeleteModal | bool | false | Controls delete confirmation modal visibility |
$userToDelete | int|null | null | ID of user pending deletion |
Query String Parameters
The component syncs the following properties with the URL query string:Public Methods
sortBy($field)
Toggles sorting by the specified field.$field(string) - The field name to sort by
- If already sorting by this field, toggles direction
- Otherwise, sets new sort field with ‘asc’ direction
confirmDelete($userId)
Opens the delete confirmation modal for a specific user.$userId(int) - The ID of the user to delete
deleteUser()
Deletes the user and closes the modal.- Deletes the user from database
- Closes the delete modal
- Flashes success message
Usage in Blade
BlogEdit
Namespace:App\Livewire\Admin\BlogEdit
Location: app/Livewire/Admin/BlogEdit.php:9
Component for editing blog posts in the admin panel.
Properties
| Property | Type | Description |
|---|---|---|
$post | Post | The post model instance being edited |
Public Methods
mount($id)
Initializes the component with a specific post.$id(int) - The ID of the post to edit
Usage in Blade
CreateUser
Namespace:App\Livewire\Admin\CreateUser
Location: app/Livewire/Admin/CreateUser.php:10
Component for creating new users with role assignment.
Properties
| Property | Type | Validation | Description |
|---|---|---|---|
$name | string | required|string|max:255 | User’s full name |
$email | string | required|email | User’s email address |
$password | string | nullable|min:8|confirmed | User’s password |
$password_confirmation | string | - | Password confirmation |
$roles | array | - | Selected role names |
$availableRoles | array | - | Available roles (excludes Super Admin) |
Public Methods
mount()
Initializes available roles.- Loads all roles except ‘Super Admin’
- Populates
$availableRolesproperty
save()
Creates a new user with assigned roles.- Creates new user in database
- Hashes password if provided
- Assigns selected roles (excluding Super Admin)
- Redirects to user list with success message
Usage in Blade
EditUser
Namespace:App\Livewire\Admin\EditUser
Location: app/Livewire/Admin/EditUser.php:10
Component for editing existing users with role management and ban/unban functionality.
Properties
| Property | Type | Validation | Description |
|---|---|---|---|
$user | User | - | The user model being edited |
$name | string | required|string|max:255 | User’s full name |
$email | string | required|email | User’s email address |
$password | string | nullable|min:8|confirmed | New password (optional) |
$password_confirmation | string | - | Password confirmation |
$status | string | - | User status (active/banned) |
$roles | array | - | Selected role names |
$availableRoles | array | - | Available roles (excludes Super Admin) |
Public Methods
mount(User $user)
Initializes the component with user data.$user(User) - The user model to edit
- Populates form fields with user data
- Loads available roles (excludes Super Admin)
- Loads user’s current roles
save()
Updates user information and roles.- Updates user name and email
- Updates password if provided
- Syncs roles (preserves Super Admin if user has it)
- Redirects to user list with success message
- Super Admin role cannot be removed from users who have it
- Super Admin role cannot be assigned to users who don’t have it
ban($id)
Bans a user by setting their status to ‘banned’.$id(int) - The ID of the user to ban
unban()
Unbans the current user.- Sets user status to ‘active’
- Redirects to user list with success message
Usage in Blade
SearchUsers
Namespace:App\Livewire\Admin\SearchUsers
Location: app/Livewire/Admin/SearchUsers.php:8
Simple search component for finding users.
Properties
| Property | Type | Default | Description |
|---|---|---|---|
$search | string | '' | Search query |
Usage in Blade
ShowUser
Namespace:App\Livewire\Admin\ShowUser
Location: app/Livewire/Admin/ShowUser.php:8
Displays detailed information about a specific user.
Properties
| Property | Type | Description |
|---|---|---|
$user | User | The user model to display |
Public Methods
mount(User $user)
Initializes the component with user data.Usage in Blade
UploadPhoto
Namespace:App\Livewire\Admin\UploadPhoto
Location: app/Livewire/Admin/UploadPhoto.php:11
Component for uploading photos to the gallery using Spatie Media Library.
Properties
| Property | Type | Validation | Description |
|---|---|---|---|
$image | UploadedFile | image|max:20480 | Image file (max 20MB) |
Traits Used
WithFileUploads- Enables file upload functionality
Public Methods
save()
Uploads the photo and creates a database record.- Validates image file
- Creates new Photo model
- Adds image to ‘images’ collection using Spatie Media Library
- Stores in ‘public’ disk
- Redirects to photo gallery with success message
Usage in Blade
BlogList
Namespace:App\Livewire\Admin\BlogList
Location: app/Livewire/Admin/BlogList.php:7
Displays a list of blog posts in the admin panel.
Usage in Blade
UserProfile
Namespace:App\Livewire\Admin\UserProfile
Location: app/Livewire/Admin/UserProfile.php:7
Displays user profile information in the admin panel.
Usage in Blade
URLShortener
Namespace:App\Livewire\Admin\URLShortener
Location: app/Livewire/Admin/URLShortener.php:7
Component for managing URL shortening functionality.