Installation
composer require appverk/components
Ensure your composer.json includes "minimum-stability": "dev" if testing unreleased features.
Service Provider
Register the package in config/app.php under providers:
AppVerk\Components\ComponentsServiceProvider::class,
Publish Config (Optional)
php artisan vendor:publish --provider="AppVerk\Components\ComponentsServiceProvider" --tag="config"
Check config/components.php for default settings.
First Use Case
Use the Component facade to render a basic component:
use AppVerk\Components\Facades\Component;
// In a Blade view
{{ Component::make('alert')->with(['type' => 'success', 'message' => 'Hello!']) }}
Registering Components
Define components in config/components.php:
'components' => [
'alert' => [
'view' => 'components.alert',
'data' => ['type' => 'info', 'message' => 'Default alert'],
],
'card' => [
'view' => 'components.card',
'data' => ['title' => 'Default Card'],
],
],
Dynamically register via service provider:
$this->app->singleton('components.alert', function () {
return new AlertComponent();
});
Blade Integration
Use the @component directive for cleaner syntax:
@component('alert', ['type' => 'warning', 'message' => 'Custom message'])
@slot('title') Custom Title @endslot
@endcomponent
Component::make('card')
->with(['title' => 'Dynamic Card'])
->withSlots(['content' => 'Dynamic content']);
@component('card')
@slot('content')
<p>Slot content</p>
@endslot
@endcomponent
Extend functionality via events:
// Listen for component rendering
event(new ComponentRendering('alert'));
// Fire custom events
Component::make('alert')->fire('alert.rendered');
View Paths
Ensure component views exist in resources/views/components/ or specify full paths in config:
'view' => 'path.to.component',
Caching Issues Clear config cache after changes:
php artisan config:clear
Data Overrides
Later with() calls override earlier ones. Use merge() for partial updates:
Component::make('card')->merge(['title' => 'Updated']);
dd(\AppVerk\Components\ComponentsManager::getComponents());
Component::make('alert')->debug(); // Dumps data to logs
Custom Component Classes
Extend \AppVerk\Components\Component:
class CustomComponent extends \AppVerk\Components\Component {
public function customMethod() { ... }
}
Register via service provider.
Middleware for Components Apply middleware to specific components:
Component::make('admin-panel')->middleware('auth.admin');
View Compilation Override default Blade compilation by publishing assets:
php artisan vendor:publish --provider="AppVerk\Components\ComponentsServiceProvider" --tag="assets"
How can I help you explore Laravel packages today?