Installation Add the package via Composer:
composer require blast-project/blast-extras
Publish the config (if available) with:
php artisan vendor:publish --provider="BlastProject\BlastExtras\BlastExtrasServiceProvider"
Key Features Overview
blast()->helper('slugify')).Collection, String) with custom methods.Blast::macro()).blast:generate).First Use Case
Extend a Collection with a custom method:
use BlastProject\BlastExtras\Facades\Blast;
Blast::macro('Collection', 'chunkByKey', function ($key) {
return $this->groupBy($key)->map(fn ($group) => $group->values());
});
// Usage:
$chunks = collect([1, 2, 3])->chunkByKey('id'); // Hypothetical example
Macro Registration
boot() method:
public function boot()
{
Blast::macro('String', 'toKebabCase', fn ($string) => Str::of($string)->kebab());
}
Blast::macro('Collection', 'filterByUser', function ($userId) {
return $this->where('user_id', $userId);
});
Helper Utilization
$slug = blast()->helper('slugify', 'Hello World'); // Returns 'hello-world'
$slug = Blast::helper('slugify', 'Hello World');
Artisan Integration
php artisan blast:generate resource Post --api
Testing Macros
Blast::macro('Collection', 'testMacro', fn () => collect(['mocked']));
$this->assertEquals(['mocked'], collect([])->testMacro());
UserCollection::scopedByRole()).App\Macros\chunkByKey).Blast::macro('Collection', 'expensiveCalc', function () {
return cache()->remember("expensive_{$this->id}", now()->addHours(1), fn () => $this->sum('price'));
});
Macro Overwriting
hasMacro() to check:
if (!collect([])->hasMacro('chunkByKey')) {
Blast::macro('Collection', 'chunkByKey', ...);
}
Facade vs. Helper Ambiguity
Blast::helper() over blast()->helper() for clarity in static analysis tools.Artisan Command Collisions
blast:make vs. make:blast). Use --command flag:
php artisan blast:generate --command=blast:make
GPL-3.0 License Implications
dd(collect([])->getMacro('chunkByKey')); // Inspect registered macros
blast()->debugHelpers(); // Logs all available helpers (if implemented)
Custom Helpers
config/blast-extras.php):
'helpers' => [
'customHelper' => function ($input) {
return strtoupper($input);
},
],
Blast::addHelper('customHelper', fn ($input) => strtoupper($input));
Macro Namespacing
Blast::macro('App\Models\User', 'isAdmin', fn () => $this->role === 'admin');
Event Listeners
Events::listen() in a service provider.Testing Utilities
Blast::flushMacros() to reset macros between tests:
public function tearDown(): void
{
Blast::flushMacros();
parent::tearDown();
}
How can I help you explore Laravel packages today?