Installation Add the package via Composer:
composer require dualhand/reusable-bundle
Register the bundle in config/app.php under providers:
DualHand\ReusableBundle\ReusableBundle::class,
Publish Assets (if applicable) Run:
php artisan vendor:publish --provider="DualHand\ReusableBundle\ReusableBundle" --tag=config
This generates a config file at config/reusable-bundle.php.
First Use Case Use the bundle’s core functionality (e.g., a reusable service or trait) in a controller or service:
use DualHand\ReusableBundle\Services\ReusableService;
class ExampleController extends Controller
{
public function index(ReusableService $reusableService)
{
$result = $reusableService->doSomething();
return response()->json($result);
}
}
Service Integration
Bind the bundle’s services in AppServiceProvider for dependency injection:
public function register()
{
$this->app->bind(
DualHand\ReusableBundle\Contracts\ReusableContract::class,
DualHand\ReusableBundle\Services\ReusableService::class
);
}
Configuration-Driven Logic
Use the published config (config/reusable-bundle.php) to customize behavior:
// Example: Override default settings
'default_setting' => env('REUSABLE_SETTING', 'fallback_value'),
Event Listeners
Subscribe to bundle events (if provided) in EventServiceProvider:
protected $listen = [
'DualHand\ReusableBundle\Events\ReusableEvent' => [
'App\Listeners\HandleReusableEvent',
],
];
Middleware (if applicable) Apply bundle-specific middleware to routes:
Route::middleware(['reusable.middleware'])->group(function () {
// Routes requiring the middleware
});
Traits for Reusability Extend bundle traits in your models/services:
use DualHand\ReusableBundle\Traits\ReusableTrait;
class MyModel extends Model
{
use ReusableTrait;
}
Namespace Conflicts
Ensure the bundle’s namespaces (DualHand\ReusableBundle\*) don’t clash with your project. Use fully qualified namespaces where needed.
Missing Config Publishing
If the bundle requires configuration but you skipped vendor:publish, default values may not behave as expected. Always publish config after installation.
Service Provider Order
The ReusableBundle provider must be loaded after Laravel’s core providers (e.g., AppServiceProvider). Check config/app.php for correct ordering.
Undefined Methods/Classes The package is labeled as a "demo bundle," so some features may be incomplete or undocumented. Verify available classes/methods in the source:
// Example: Check if a class/method exists before use
if (class_exists(DualHand\ReusableBundle\Services\ReusableService::class)) {
// Safe to use
}
Enable Debug Mode
Set APP_DEBUG=true in .env to surface bundle-related errors or warnings.
Log Bundle Output Use Laravel’s logging to trace bundle behavior:
\Log::debug('ReusableBundle output:', ['data' => $reusableService->getData()]);
Check for Deprecated Features
Since the bundle is a demo, some APIs may change. Review the README or source for deprecation notices.
Customizing Services
Override bundle services by binding interfaces to your implementations in AppServiceProvider:
$this->app->bind(
DualHand\ReusableBundle\Contracts\ReusableContract::class,
App\Services\CustomReusableService::class
);
Adding New Features Extend bundle classes (e.g., traits or services) in your project:
namespace App\Extensions;
use DualHand\ReusableBundle\Traits\ReusableTrait;
trait ExtendedReusableTrait
{
public function extraMethod()
{
// Add custom logic
}
}
Testing the Bundle Mock bundle dependencies in tests:
$this->app->instance(
DualHand\ReusableBundle\Contracts\ReusableContract::class,
Mockery::mock(DualHand\ReusableBundle\Contracts\ReusableContract::class)
);
How can I help you explore Laravel packages today?