Installation:
composer require tcg/voyager
php artisan voyager:install --author="Your Name" --email="your@email.com"
php artisan migrate
First Use Case:
/admin (default credentials: admin@admin.com / password).Settings, Users, Roles, Permissions).Key Files to Explore:
app/Voyager/ – Core models, policies, and service providers.resources/views/voyager/ – Blade templates for admin UI.config/voyager.php – Configuration for routes, menus, and BREAD settings.BREAD Management:
php artisan voyager:make {ModelName}
App\{ModelName}.app/Voyager/{ModelName}Controller.php and resources/views/voyager/{model-name}/.addRow() in the controller to modify fields:
public function setDisplayColumn($data)
{
return $data->title; // Override default display column
}
Menu and Dashboard:
// In a Service Provider (e.g., AppServiceProvider)
Voyager::addMenuItem('dashboard', 'Reports', route('voyager.reports.index'));
Voyager\Widgets\BaseWidget and register in config/voyager.php under dashboard.Permissions & Roles:
Route::group(['middleware' => ['voyager.auth']], function () {
// Admin-only routes
});
API Integration:
/api/voyager/{model}) or create custom API routes:
Route::apiResource('custom-api', 'CustomApiController');
Laravel Mix/Webpack:
php artisan vendor:publish --tag=voyager-assets
resources/assets/sass/voyager/custom.scss.Multi-Tenancy:
tenant() helper or middleware to scope data per tenant.Localization:
php artisan vendor:publish --tag=voyager-translations
config/voyager.php for custom locales.Vue/JS Dependencies:
// In resources/js/app.js
window.Voyager = { /* Override defaults */ };
Database Schema Assumptions:
id, created_at, updated_at fields. Custom models may need adjustments:
public function setTable()
{
return 'custom_table_name';
}
Caching Issues:
php artisan voyager:clear-cache
Permission Overrides:
// app/Policies/VoyagerPolicy.php
public function viewAny(User $user)
{
return $user->hasRole('admin');
}
Log Viewer:
/admin/log-viewer to debug BREAD actions or API calls.Query Logging:
config/voyager.php:
'debug' => env('APP_DEBUG', true),
Common Errors:
RouteServiceProvider includes Voyager’s routes:
Route::group(['prefix' => 'admin'], function () {
Voyager::routes();
});
php artisan session:clear
Custom BREAD Actions:
public function getBreadActions()
{
return [
'edit' => [
'title' => 'Custom Action',
'icon' => 'voyager-edit',
'route' => ['voyager.{resource}.custom', $this->data],
],
];
}
Event Listeners:
voyager.data.displaying):
VoyagerEvents::addListener('voyager.data.displaying', function ($event) {
$event->data->custom_field = 'modified';
});
API Extensions:
app/Http/Controllers/Voyager/{Model}ApiController.php.Theme Customization:
resources/views/vendor/voyager/ to resources/views/voyager/.How can I help you explore Laravel packages today?