Installation
composer require badpixxel/paddock-mysql
Add the service provider to config/app.php:
'providers' => [
// ...
Badpixxel\Paddock\PaddockServiceProvider::class,
],
First Use Case: Query Builder Extension Extend Laravel’s query builder with Paddock’s SQL capabilities:
use Badpixxel\Paddock\Paddock;
$query = Paddock::table('users')
->select('*')
->where('active', true)
->paginate(10); // Example: Hypothetical Paddock-specific method
Key Files to Review
config/paddock.php (if provided) for default configurations.src/Paddock.php for core functionality and available methods.src/QueryBuilder.php for query builder extensions.$users = Paddock::table('users')
->whereHasPivot('roles', 'name', 'admin') // Hypothetical Paddock method
->orderByPivot('created_at', 'desc') // Hypothetical Paddock method
->get();
$query = Paddock::table('orders')
->filterByStatus(['pending', 'shipped']) // Hypothetical method
->filterByDateRange($startDate, $endDate); // Hypothetical method
use Badpixxel\Paddock\Traits\Paddockable;
class User extends Model {
use Paddockable;
public function scopeActive($query) {
return $query->paddockActive(); // Hypothetical Paddock scope
}
}
$activeUsers = User::active()->paginate(20);
$results = Paddock::table('posts')
->joinPivotTable('post_tags', 'tags') // Hypothetical method
->wherePivot('tags.name', 'laravel')
->get();
Paddock::table('users')
->where('last_login', '<', now()->subDays(30))
->updatePaddock(['status' => 'inactive']); // Hypothetical method
public function index(Request $request) {
$query = Paddock::table('products');
$this->applyPaddockFilters($request, $query); // Custom method
return $query->paginate($request->input('per_page', 15));
}
Method Name Collisions
paginate() or orderBy(). Ensure they don’t conflict with Laravel’s built-ins. Prefix or alias if needed:
$query->paddockPaginate(10); // Hypothetical workaround
SQL Injection Risks
where(), filterBy*()) instead of raw SQL strings. Avoid:
Paddock::table('users')->where("1=1; DROP TABLE users"); // ❌ Dangerous
Lack of Documentation
src/QueryBuilder.php) for method signatures.Performance Overhead
// Before:
$query = Paddock::table('large_table')->complexFilter();
// After (optimized):
$query = DB::table('large_table')->whereRaw('...'); // Fallback to raw SQL if needed
Enable Query Logging
Add to config/database.php:
'logging' => true,
Then inspect logged queries in storage/logs/laravel.log.
Inspect Generated SQL
Use Laravel’s toSql() and getBindings():
$sql = $query->toSql();
$bindings = $query->getBindings();
dd(compact('sql', 'bindings'));
Fallback to Raw SQL If Paddock’s methods fail, drop to Laravel’s query builder:
DB::table('users')->where('active', true)->get();
Custom Query Macros Extend Paddock’s query builder globally:
use Badpixxel\Paddock\Paddock;
Paddock::macro('customFilter', function ($field, $value) {
return $this->where($field, $value);
});
Usage:
$query = Paddock::table('users')->customFilter('role', 'admin');
Model Observers Hook into Paddock’s events (if supported) to add logic:
class UserObserver {
public function saving(User $user) {
if ($user->isDirty('status')) {
// Custom Paddock logic
}
}
}
Configuration Overrides
Override defaults in config/paddock.php (if the package provides one):
'default_limit' => 50,
'soft_deletes' => false,
Testing Mock Paddock’s query builder in tests:
$mock = Mockery::mock('overload', Badpixxel\Paddock\Paddock::class);
$mock->shouldReceive('table')->andReturn(DB::table('users'));
How can I help you explore Laravel packages today?