🛠️

Global Helpers & Classes

A comprehensive, premium suite of helper functions and classes carefully designed to accelerate date management, secure HTML sanitization, formatted currency printing, image resizing, and SEO optimization.

📅 Date Helpers 📝 Formatting Helpers ⚙️ General Helpers 🖼️ Image & Storage 🔍 SEO & Schemas

📅 Date & Time Helpers

format_date($date, string $format = 'M d, Y') Global Wrapper

Formats a date string, Carbon instance, or timestamp into a consistent display structure. Backed by DateHelper::format().

// Output: "Jun 20, 2026" echo format_date('2026-06-20 14:30:00'); // Output: "2026-06-20" echo format_date(now(), 'Y-m-d');
time_ago($timestamp) Global Wrapper

Calculates a human-friendly diffForHumans() string (e.g., "2 hours ago"). Backed by DateHelper::timeAgo().

// Output: "3 hours ago" echo time_ago(now()->subHours(3));
DateHelper::toUserTimezone($date, ?string $timezone = null) Static Class Method

Converts raw date objects to the target timezone (falls back to config('app.timezone')).

use App\Helpers\DateHelper; $userTime = DateHelper::toUserTimezone('2026-06-20 12:00:00', 'Asia/Dhaka');
DateHelper::isPast($date) Static Class Method

Checks whether a date is in the past.

if (DateHelper::isPast($task->deadline)) { // handle overdue }
DateHelper::age($birthDate) Static Class Method

Computes the age based on a birth date.

// Output: 31 echo DateHelper::age('1995-10-15');

📝 Formatting & String Helpers

clean_html(string $html, array $allowedTags = ['p', 'br', 'strong', 'em', 'a']) Global Wrapper

Strips out harmful HTML tags to shield against cross-site scripting (XSS), keeping only defined allowed formatting tags.

// Output: "Hello World" echo clean_html('Hello <script>evil()</script> <strong>World</strong>');
generate_slug(string $title, string $separator = '-') Global Wrapper

Transforms text titles into slug components for SEO-friendly URLs. Backed by FormatHelper::generateSlug().

// Output: "super-secure-laravel-starter-kit" echo generate_slug('Super Secure Laravel Starter Kit!');
truncate_text(string $text, int $limit = 100, string $ending = '...') Global Wrapper

Shortens strings to a length limit while preventing character clipping. Backed by FormatHelper::truncate().

// Output: "Laravel is a..." echo truncate_text('Laravel is a PHP framework designed for web artisans.', 15);
mask_string(string $string, int $visibleChars = 3, string $maskChar = '*') Global Wrapper

Masks sensitive inputs (such as tokens, emails, or digits) keeping a prefix visible.

// Output: "adm********" echo mask_string('adminsecretpwd', 3);
FormatHelper::htmlToText(string $html) Static Class Method

Strips all HTML tags and trims spacing to retrieve raw, plain text contents.

use App\Helpers\FormatHelper; // Output: "Click Here" echo FormatHelper::htmlToText('<a href="#">Click Here</a>');

⚙️ General & Math Utilities

format_money($amount, ?string $currency = null, ?string $locale = null) Global Wrapper

Formats decimals into currency representations, using PHP's NumberFormatter. Backed by GeneralHelper::formatMoney().

// Output: "$1,250.50" (assuming default USD/en_US settings) echo format_money(1250.50); // Output: "1.250,50 €" echo format_money(1250.50, 'EUR', 'de_DE');
calculate_percentage($part, $total, int $precision = 2) Global Wrapper

Safely calculates percentage fractions, preventing Division-by-Zero runtime exceptions.

// Output: 25.00 echo calculate_percentage(15, 60); // Output: 0.00 (Safe from crashing) echo calculate_percentage(10, 0);
get_client_ip() Global Wrapper

Resolves client IPs from requests, identifying headers from Cloudflare proxy setups or front-end reverse proxies.

$clientIp = get_client_ip();
is_mobile() Global Wrapper

Checks user agent request strings to identify mobile browsing sessions.

if (is_mobile()) { // load optimized sidebar layout }
active_route($routes, string $activeClass = 'active') Global Wrapper

Checks if the current route matches input values, returning class lists for navigation menus.

<a href="{{ route('admin.dashboard') }}" class="{{ active_route('admin.dashboard') }}">Dashboard</a>
GeneralHelper::parseVideoId(string $url) Static Class Method

Extracts embed video IDs from YouTube or Vimeo URLs.

use App\Helpers\GeneralHelper; // Output: "dQw4w9WgXcQ" echo GeneralHelper::parseVideoId('https://www.youtube.com/watch?v=dQw4w9WgXcQ');
GeneralHelper::sanitize($data) Static Class Method

Recursively HTML-encodes strings inside values or arrays for safe render output.

$safeInput = GeneralHelper::sanitize($request->all());

🖼️ Image & Storage Utilities

get_avatar($user, int $size = 100) Global Wrapper

Resolves user avatar paths. Checks database fields, falls back to Gravatar images or local fallbacks.

<img src="{{ get_avatar(auth()->user(), 80) }}" alt="Avatar">
storage_url(?string $path) Global Wrapper

Converts storage path strings to full URLs. External URLs are ignored and returned as is.

// Output: "http://domain.test/storage/avatars/avatar.png" echo storage_url('avatars/avatar.png');
file_size_human(int $bytes, int $precision = 2) Global Wrapper

Translates bytes integer counts to human readable filesizes (e.g. KB, MB, GB).

// Output: "1.48 MB" echo file_size_human(1548576);
ImageHelper::uploadImage(UploadedFile $file, string $directory, array $options = []) Static Class Method

Scales and saves files in storage with Intervention Image, preserving aspect ratios.

use App\Helpers\ImageHelper; $path = ImageHelper::uploadImage($request->file('cover'), 'covers', [ 'max_width' => 1200, 'max_height' => 800, 'quality' => 80 ]);

🔍 SEO & Schema Generators

set_seo(string $title, ?string $description = null, array $keywords = [], ?string $image = null) Global Wrapper

Bootstraps page-level SEO header variables (Meta titles, descriptions, keywords, OpenGraph items).

set_seo('Pricing Plan', 'Select our subscription plan.', ['pricing', 'plans']);
set_article_seo(string $title, string $description, string $url, ?string $image = null, ?string $publishedTime = null, ?string $author = null) Global Wrapper

Configures specific schema properties and canonical links on article pages.

set_article_seo( $post->title, $post->description, route('blog.show', $post), storage_url($post->image), $post->published_at->toIso8601String() );
structured_data(array $data) Global Wrapper

Wraps structured data arrays in inline script tags matching search engine JSON-LD requirements.

{!! structured_data([ '@context' => 'https://schema.org', '@type' => 'Organization', 'name' => 'Starter Kit Inc.', 'url' => 'https://starterkit.test' ]) !!}
SeoHelper::breadcrumbSchema(array $items) Static Class Method

Generates JSON-LD Breadcrumb schemas matching navigation lists.

use App\Helpers\SeoHelper; echo SeoHelper::breadcrumbSchema([ ['name' => 'Home', 'url' => '/'], ['name' => 'Categories', 'url' => '/categories'] ]);