1. Go to this page and download the library: Download tanthammar/laravel-extras library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
tanthammar / laravel-extras example snippets
// Find users whose email starts with 'john'
User::whereStartsWith('email', 'john')->get();
// Chain with other conditions
User::where('active', true)->orWhereStartsWith('name', 'admin')->get();
// Find users with gmail addresses
User::whereEndsWith('email', 'gmail.com')->get();
// Find users where BOTH name and email contain 'john'
User::whereAllLike(['name', 'email'], 'john')->get();
// Find users where name OR email contains 'john'
User::where('active', true)->orWhereAnyLike(['name', 'email'], 'john')->get();
// Find users where name contains both 'john' AND 'doe' (in any order)
User::whereContains('name', 'john doe')->get();
// OR condition with contains
User::where('active', true)->orWhereContains(['name', 'email'], 'john doe')->get();
// Search posts by content, title, or author name
Post::whereRelationsLike(['title', 'content', 'author.name'], 'laravel')->get();
// Find events where localized name starts with 'Summer'
Event::whereTranslatableStartsWith('name', 'Summer')->get();
// Search specific locale
Event::whereTranslatableStartsWith('name', 'Été', 'fr')->get();
// Find events where localized name contains 'festival'
Event::whereTranslatableLike('name', 'festival')->get();
// Find events where localized name contains 'music festival' (both words)
Event::whereTranslatableContains('name', 'music festival')->get();
// Find bookings that overlap with a specific date range
Booking::whereOverlaps('start_date', 'end_date', '2024-01-01', '2024-01-31')->get();
// Check if user exists by ID
if (User::existsById(123)) {
// User exists
}
// Check if record exists by UUID
if (Product::existsByUuid('550e8400-e29b-41d4-a716-446655440000')) {
// Product exists
}
// Sort by translated name field
Event::orderByTranslation('name', 'asc')->get();
// Sort by regular field with locale collation
User::orderByLocale('name', 'desc')->get();
use TantHammar\LaravelExtras\NoWhiteSpace;
$clean = NoWhiteSpace::clean("Hello\n\tWorld ");
// Result: 'HelloWorld'
use TantHammar\LaravelExtras\MarkdownToHtmlString;
$html = new MarkdownToHtmlString('**Bold text** with [link](https://example.com)');
// Use in Blade templates
{!! $html !!}
// Filament placeholder field example
Placeholder::make(trans('fields.accounting-chart'))
->disableLabel()
->content(new MarkdownToHtmlString(__('fields.account_hint')))
->columnSpan('full')