Installation via Composer
composer require dimassrio/vanilla
git clone -b 2.1 https://github.com/dimassrio/vanilla.git
Publish Assets Run the package’s installer (if included) or manually publish:
php artisan vendor:publish --provider="Vanilla\VanillaServiceProvider" --tag=public
php artisan vendor:publish --provider="Vanilla\VanillaServiceProvider" --tag=migrations
config/vanilla.php exists and update database credentials.Run Migrations
php artisan migrate
database/migrations/ for Vanilla-specific tables (e.g., Discussions, Comments).First Use Case: Embedding a Forum Add the Vanilla widget to a Laravel Blade view:
@vanilla('forum', ['id' => 'community-discussions', 'title' => 'Community Chat'])
resources/js/vanilla.js).Forum Embedding
$vanilla = app(\Vanilla\Contracts\VanillaClient::class);
$discussions = $vanilla->getDiscussions(['limit' => 5]);
@vanilla directives for seamless rendering:
// In AppServiceProvider::boot()
Blade::directive('vanilla', function ($expression) {
return "<?php echo app(\Vanilla\View\VanillaRenderer::class)->render($expression); ?>";
});
Authentication Sync
Auth facade to sync users:
$vanillaUser = $vanilla->createUser([
'Name' => auth()->user()->name,
'Email' => auth()->user()->email,
'Password' => Str::random(12),
]);
Route::middleware(['auth'])->group(function () {
Route::prefix('vanilla')->group(function () {
// Vanilla routes here
});
});
Plugin/Theming
// resources/js/app.js
require('@vanilla/vanilla-theme');
require('./custom-vanilla-theme');
// Listen to Vanilla's 'DiscussionCreated' event
event(new \Vanilla\Events\DiscussionCreated($discussion));
Branch Dependency
master may introduce unstable features.2.1 branch for production:
composer require dimassrio/vanilla:2.1.*
Asset Conflicts
// webpack.mix.js
mix.js('resources/js/vanilla.js', 'public/js')
.sass('resources/scss/vanilla.scss', 'public/css');
Database Schema Mismatches
// config/vanilla.php
'database' => [
'prefix' => 'vanilla_',
];
Logging
Enable Vanilla’s debug mode in config/vanilla.php:
'debug' => env('APP_DEBUG', false),
storage/logs/vanilla.log.API Rate Limiting
$discussions = Cache::remember('vanilla_discussions', now()->addHours(1), function () {
return $vanilla->getDiscussions();
});
Plugin Development
Hook system via Laravel’s service providers:
// app/Providers/VanillaHookProvider.php
public function register()
{
\Vanilla\Hook::add('DiscussionController_BeforeSave', function ($sender, $args) {
// Modify discussion data
$args['Discussion']['Tags'] = 'laravel';
});
}
CORS Issues
config/vanilla.php:
'cors' => [
'allowed_origins' => ['https://your-laravel-app.com'],
],
Asset Versioning
'assets' => [
'versioning' => false,
],
Localization
lang directory:
resources/lang/en/vanilla.php
How can I help you explore Laravel packages today?