cyberpunkcodes/laravel-menu-helper
Build dynamic menus in Laravel from config arrays or runtime data. Supports basic and multi-level navs with view components, helpers for active route detection, dropdown/children handling, and easy customization (RBAC, DB-backed items, caching).
For a Laravel developer, start by installing the package via Composer:
composer require vendor/package-name
Publish the package's configuration (if applicable) with:
php artisan vendor:publish --provider="Vendor\PackageName\PackageServiceProvider"
Review the config/package-name.php file for core settings. The package likely includes a facade (e.g., PackageName) for easy access to its primary functionality. Test the basic usage in routes/web.php or a controller:
use Vendor\PackageName\Facades\PackageName;
Route::get('/test', function () {
return PackageName::someCoreFeature();
});
Check the package’s README.md for a "Quick Start" section or example use cases.
Service Integration
Bind the package’s services in AppServiceProvider for dependency injection:
public function register()
{
$this->app->bind('custom.package.service', function ($app) {
return new \Vendor\PackageName\Services\CustomService();
});
}
Use the service in controllers or commands:
use Illuminate\Support\Facades\Auth;
use Vendor\PackageName\Services\CustomService;
public function __construct(CustomService $service)
{
$this->service = $service;
}
Event Listeners
Listen to the package’s events (if provided) in EventServiceProvider:
protected $listen = [
'Vendor\PackageName\Events\PackageEvent' => [
'App\Listeners\HandlePackageEvent',
],
];
Middleware
Use the package’s middleware (if included) in app/Http/Kernel.php:
protected $middleware = [
// ...
\Vendor\PackageName\Http\Middleware\CheckPackagePermission::class,
];
Artisan Commands Run the package’s commands (e.g., for migrations, caching, or utilities):
php artisan package-name:command --option=value
use Vendor\PackageName\Rules\CustomRule;
$request->validate([
'field' => ['required', new CustomRule],
]);
Configuration Overrides
Avoid hardcoding values in your application. Always use the published config file (config/package-name.php) for settings like API keys, timeouts, or feature flags. Override defaults in config/package-name.php:
'api' => [
'timeout' => 30, // Override default
],
Namespace Collisions
If the package uses similar class names (e.g., Service, Helper), alias them in your code to avoid ambiguity:
use Vendor\PackageName\Services\Service as PackageService;
Dependency Conflicts
Ensure the package’s PHP version and Laravel version requirements match your project. Check composer.json for constraints like:
"require": {
"php": "^8.0",
"laravel/framework": "^9.0"
}
Caching Quirks If the package caches data, clear Laravel’s cache after updates:
php artisan cache:clear
php artisan config:clear
config/package-name.php to log package activities:
'debug' => env('APP_DEBUG', false),
php artisan container:dump
php artisan tinker
>>> event(new \Vendor\PackageName\Events\PackageEvent());
Customizing Services Extend the package’s services by binding your own implementations:
$this->app->singleton('vendor.package.service', function ($app) {
return new App\Services\ExtendedPackageService(
$app->make('vendor.package.service')
);
});
Adding Views/Blades
Publish the package’s views (if included) and override them in resources/views/vendor/package-name:
php artisan vendor:publish --tag=package-views
Custom Events Extend the package’s event system by creating your own listeners or events that interact with its core events.
Testing Use the package’s test utilities (if provided) or mock its services in PHPUnit:
$this->mock(Vendor\PackageName\Services\CustomService::class)
->shouldReceive('process')
->once();
How can I help you explore Laravel packages today?