DashboardService

Table of contents

  1. Overview
  2. Public Methods
  3. Related Components
  4. Notes


1. Overview Table of Contents

The DashboardService class provides helper functions for administrative dashboard operations, including access restrictions and paginated user management. It ensures that the logged-in admin user cannot edit or view their own profile via the dashboard and supports user list pagination.

Setup

use Core\Services\DashboardService;

Common Use Cases

  • Prevent the logged-in admin from editing or viewing their own profile via the dashboard.
  • Retrieve a paginated list of all users excluding the current admin.
  • Get a count of users for dashboard summaries and stats.


2. ⚙️ Public Methods Table of Contents

checkIfCurrentUser(Users $user, string $redirect = ''): void

Prevents the current logged-in user from viewing or editing their own user record via the admin dashboard. If the given user matches the currently logged-in user, a danger flash message is set and a redirect occurs.

DashboardService::checkIfCurrentUser($user, 'admindashboard.users');


paginateUsers(Pagination $pagination): array

Returns an array of paginated users, excluding the currently logged-in admin. Sorting is done in descending order by created_at.

$users = DashboardService::paginateUsers($pagination);


totalUserCountExceptCurrent(): int

Returns the total number of users in the system, excluding the currently logged-in admin. This can be used for admin dashboard statistics or analytics.

$count = DashboardService::totalUserCountExceptCurrent();


  • AuthService::currentUser() – Used to identify and exclude the current user in queries.
  • Pagination – Responsible for paginating the user listing queries.
  • Users – Eloquent-style model for fetching and counting user records.


4. 🧠 Notes Table of Contents

  • All queries exclude the current logged-in user to prevent unintentional self-editing or display within administrative lists.
  • The pagination relies on the Pagination class to generate SQL query parameters for the Users model.
  • This service is intentionally minimal and can be extended with additional dashboard-specific helper methods such as widget registration, statistics blocks, or activity feeds.