PHP code example of nyoncode / laravel-package-toolkit
1. Go to this page and download the library: Download nyoncode/laravel-package-toolkit library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
nyoncode / laravel-package-toolkit example snippets
use NyonCode\LaravelPackageToolkit\PackageServiceProvider;
use NyonCode\LaravelPackageToolkit\Packager;
use NyonCode\LaravelPackageToolkit\Contracts\Packable;
class MyAwesomePackageServiceProvider extends PackageServiceProvider implements
Packable
{
public function configure(Packager $packager): void
{
$packager
->name('My Awesome Package')
->hasConfig()
->hasRoutes()
->hasMigrations()
->hasTranslations()
->hasViews();
}
}
use NyonCode\LaravelPackageToolkit\PackageServiceProvider;
use NyonCode\LaravelPackageToolkit\Packager;
use NyonCode\LaravelPackageToolkit\Contracts\Packable;
class AdvancedPackageServiceProvider extends PackageServiceProvider implements
Packable
{
public function configure(Packager $packager): void
{
$packager
->name('Advanced package')
->hasShortName('adv-pkg')
->hasConfig('custom-config.php')
->hasRoutes(['api.php', 'web.php'])
->hasMigrations('custom-migrations')
->hasTranslations('lang')
->hasViews('custom-views')
->hasComponents([
'data-table' => DataTable::class,
'modal' => Modal::class,
]);
}
public function registeringPackage(): void
{
// Custom logic before package registration
}
public function bootingPackage(): void
{
// Custom logic before package boot
}
}
use NyonCode\LaravelPackageToolkit\PackageServiceProvider;
use NyonCode\LaravelPackageToolkit\Packager;
use NyonCode\LaravelPackageToolkit\Contracts\Packable;
class ConditionalPackageServiceProvider extends PackageServiceProvider implements
Packable
{
public function configure(Packager $packager): void
{
$packager
->name('Conditional package')
->hasRoutes(['api.php', 'web.php'])
->hasMigrations('custom-migrations')
->hasTranslations('lang')
->hasViews('custom-views')
->when($this->isInLocal(), function ($packager) {
$packager->hasConfig('local-config.php');
$packager->hasCommands();
})->when($this->isInProduction(), function ($packager) {
$packager->hasConfig('production-config.php');
$packager->hasRoutes('web.php');
});
}
}
$packager
// Custom command name
->installCommandName('setup') // Creates package:setup instead of package:install
// Hide command from artisan list
->installCommandHidden(true)
// Auto-install when package loads
->installOnRun(true)
// Install only in specific environments
->installOnRunInEnvironment(['local', 'testing'])
->installOnRunInLocal()
->installOnRunInProduction();
// Quick install (config, migrations, assets)
$packager->hasQuickInstall();
// Full install (everything)
$packager->hasFullInstall();
// Minimal install (config only)
$packager->hasMinimalInstall();
// Development install (config, migrations, views, assets, routes in local only)
$packager->hasDevInstall();