alexeyshockov/colada-x
colada-x is a tiny Laravel/PHP helper package by alexeyshockov. Lightweight and experimental, it offers small utilities you can drop into a project quickly. Best for tinkerers who don’t mind minimal docs, few stars, and a still-maturing API.
Installation Add the package via Composer:
composer require alexeyshockov/colada-x
Register the service provider in config/app.php under providers:
Alexeyshockov\ColadaX\ColadaXServiceProvider::class,
First Use Case
Simplify a callback using the colada() helper. For example, replace a verbose closure with a cleaner syntax:
use ColadaX;
// Before
$result = $array->map(function ($item) {
return $item->name;
});
// After
$result = $array->map(ColadaX::name);
Where to Look First
ColadaX facade or helper for supported property/accessor shortcuts.Property Access
Replace nested property access with colada():
// Before
$array->map(function ($item) {
return $item->user->name;
});
// After
$array->map(ColadaX::user->name);
Method Chaining
Use colada() for method calls in callbacks:
$array->filter(ColadaX::isActive);
Dynamic Callbacks Pass dynamic keys or methods:
$key = 'email';
$array->map(ColadaX::$key);
Integration with Collections Works seamlessly with Laravel Collections:
$users = User::all();
$names = $users->pluck(ColadaX::name);
colada() for cleaner, more maintainable code.return response()->json($posts->map(ColadaX::title));
$this->validate($request, [
'user.name' => 'required',
'user.email' => 'email',
]);
// Simplified with ColadaX in custom validation logic.
No Dynamic Method Resolution
ColadaX does not support dynamic method calls (e.g., ColadaX::$method()). Stick to static properties or predefined methods.
// ❌ Won't work
$method = 'getName';
ColadaX::$method; // Error
No Support for Complex Logic
Avoid using colada() for callbacks requiring logic (e.g., if-else, arithmetic). It’s designed for simple property/method access.
// ❌ Avoid
$array->filter(ColadaX::isActiveAndVerified); // Fails if method doesn't exist
Archived Package Risks
ColadaX::method fails, verify the method/property exists on the object:
dd(method_exists($item, 'method')); // Debug existence
// ❌ Fails if $item->user is null
ColadaX::user->name;
Alias the Helper
Add a shortcut in app/Providers/AppServiceProvider.php:
use ColadaX;
if (!function_exists('colada')) {
function colada($property) {
return ColadaX::{$property};
}
}
Now use colada('name') instead of ColadaX::name.
Extend Functionality Create a wrapper class for custom logic:
class CustomColada {
public static function fullName($item) {
return "{$item->first_name} {$item->last_name}";
}
}
Use CustomColada::fullName alongside ColadaX.
Fallback for Missing Properties
Handle potential null values gracefully:
$array->map(function ($item) {
return ColadaX::user?->name ?? 'N/A';
});
Testing
Mock ColadaX in tests:
$this->partialMock(ColadaX::class, ['name'])
->shouldReceive('name')
->andReturn('Mocked Name');
How can I help you explore Laravel packages today?