PHP code example of roundly-consulting / package-toolkit-for-laravel

1. Go to this page and download the library: Download roundly-consulting/package-toolkit-for-laravel 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/ */

    

roundly-consulting / package-toolkit-for-laravel example snippets


use RoundlyConsulting\PackageToolkit\Concerns\RegistersBlueprintMacros;
use RoundlyConsulting\PackageToolkit\Package;
use RoundlyConsulting\PackageToolkit\PackageServiceProvider;

final class CommentsServiceProvider extends PackageServiceProvider
{
    use RegistersBlueprintMacros;

    public function configurePackage(Package $package): void
    {
        $package
            ->name('comments')                   // tags: comments-config, comments-migrations, …
            ->hasConfigFile()
            ->hasMigrations()
            ->hasTranslations()
            ->hasCommands([PruneCommentsCommand::class])
            ->contributesToAbout();
    }

    public function boot(): void
    {
        parent::boot();

        $this->registerBlueprintMacros();       // morphKey(), ownerKey(), auditable(), …
    }
}

use RoundlyConsulting\PackageToolkit\Enums\KeyType;
use RoundlyConsulting\PackageToolkit\Support\Config;

Schema::create('comments', function (Blueprint $table): void {
    $table->id();
    $table->morphKey('commentable', KeyType::fromConfig('comments.key_type'));  // bigint, uuid or ulid pair
    $table->text('body');
    $table->auditable();                                                          // timestamps + soft deletes
});

Config::integer('comments.per_page', 20, min: 1, max: 100);   // '20' → 20; 'five' throws, never falls back