Skip to main content

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

PropertyTypeDefaultDescription
$searchstring''Search query for filtering users by name or email
$sortFieldstring'name'Field to sort by
$sortDirectionstring'asc'Sort direction (asc/desc)
$showDeleteModalboolfalseControls delete confirmation modal visibility
$userToDeleteint|nullnullID of user pending deletion

Query String Parameters

The component syncs the following properties with the URL query string:
protected $queryString = [
    'search' => ['except' => ''],
    'sortField' => ['except' => 'name'],
    'sortDirection' => ['except' => 'asc'],
];

Public Methods

sortBy($field)

Toggles sorting by the specified field.
public function sortBy($field)
Parameters:
  • $field (string) - The field name to sort by
Behavior:
  • 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.
public function confirmDelete($userId)
Parameters:
  • $userId (int) - The ID of the user to delete

deleteUser()

Deletes the user and closes the modal.
public function deleteUser()
Effects:
  • Deletes the user from database
  • Closes the delete modal
  • Flashes success message

Usage in Blade

<livewire:admin.user-list />

BlogEdit

Namespace: App\Livewire\Admin\BlogEdit Location: app/Livewire/Admin/BlogEdit.php:9 Component for editing blog posts in the admin panel.

Properties

PropertyTypeDescription
$postPostThe post model instance being edited

Public Methods

mount($id)

Initializes the component with a specific post.
public function mount($id)
Parameters:
  • $id (int) - The ID of the post to edit

Usage in Blade

<livewire:admin.blog-edit :id="$postId" />

CreateUser

Namespace: App\Livewire\Admin\CreateUser Location: app/Livewire/Admin/CreateUser.php:10 Component for creating new users with role assignment.

Properties

PropertyTypeValidationDescription
$namestringrequired|string|max:255User’s full name
$emailstringrequired|emailUser’s email address
$passwordstringnullable|min:8|confirmedUser’s password
$password_confirmationstring-Password confirmation
$rolesarray-Selected role names
$availableRolesarray-Available roles (excludes Super Admin)

Public Methods

mount()

Initializes available roles.
public function mount()
Behavior:
  • Loads all roles except ‘Super Admin’
  • Populates $availableRoles property

save()

Creates a new user with assigned roles.
public function save()
Effects:
  • 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

<livewire:admin.create-user />

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

PropertyTypeValidationDescription
$userUser-The user model being edited
$namestringrequired|string|max:255User’s full name
$emailstringrequired|emailUser’s email address
$passwordstringnullable|min:8|confirmedNew password (optional)
$password_confirmationstring-Password confirmation
$statusstring-User status (active/banned)
$rolesarray-Selected role names
$availableRolesarray-Available roles (excludes Super Admin)

Public Methods

mount(User $user)

Initializes the component with user data.
public function mount(User $user)
Parameters:
  • $user (User) - The user model to edit
Behavior:
  • Populates form fields with user data
  • Loads available roles (excludes Super Admin)
  • Loads user’s current roles

save()

Updates user information and roles.
public function save()
Effects:
  • 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
Security:
  • 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’.
public function ban($id)
Parameters:
  • $id (int) - The ID of the user to ban

unban()

Unbans the current user.
public function unban()
Effects:
  • Sets user status to ‘active’
  • Redirects to user list with success message

Usage in Blade

<livewire:admin.edit-user :user="$user" />

SearchUsers

Namespace: App\Livewire\Admin\SearchUsers Location: app/Livewire/Admin/SearchUsers.php:8 Simple search component for finding users.

Properties

PropertyTypeDefaultDescription
$searchstring''Search query

Usage in Blade

<livewire:admin.search-users />

ShowUser

Namespace: App\Livewire\Admin\ShowUser Location: app/Livewire/Admin/ShowUser.php:8 Displays detailed information about a specific user.

Properties

PropertyTypeDescription
$userUserThe user model to display

Public Methods

mount(User $user)

Initializes the component with user data.
public function mount(User $user)

Usage in Blade

<livewire:admin.show-user :user="$user" />

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

PropertyTypeValidationDescription
$imageUploadedFileimage|max:20480Image file (max 20MB)

Traits Used

  • WithFileUploads - Enables file upload functionality

Public Methods

save()

Uploads the photo and creates a database record.
public function save()
Effects:
  • 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

<livewire:admin.upload-photo />
Example Form:
<form wire:submit.prevent="save">
    <input type="file" wire:model="image">
    @error('image') <span>{{ $message }}</span> @enderror
    <button type="submit">Upload Photo</button>
</form>

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

<livewire:admin.blog-list />

UserProfile

Namespace: App\Livewire\Admin\UserProfile Location: app/Livewire/Admin/UserProfile.php:7 Displays user profile information in the admin panel.

Usage in Blade

<livewire:admin.user-profile />

URLShortener

Namespace: App\Livewire\Admin\URLShortener Location: app/Livewire/Admin/URLShortener.php:7 Component for managing URL shortening functionality.

Usage in Blade

<livewire:admin.u-r-l-shortener />

Build docs developers (and LLMs) love