itcentar/larastarter

Reusable traits, migrations, enums, and actions for Laravel applications.

Maintainers

Package info

bitbucket.org/itc-solution/larastarter-package

pkg:composer/itcentar/larastarter

Statistics

Installs: 1

Dependents: 0

Suggesters: 0

v1.0.0 2026-03-09 10:46 UTC

This package is not auto-updated.

Last update: 2026-03-09 14:42:43 UTC


README

Reusable traits, actions, enums, helpers, exceptions, and scopes for Laravel applications.

Requirements

  • PHP 8.1+
  • Laravel 10, 11, or 12

Installation

composer require itcentar/larastarter

The package auto-discovers its service provider via Laravel's package discovery.

Setup

After installing, publish the migrations and enums — these are the main publishable assets most projects need:

php artisan vendor:publish --tag=larastarter-migrations
php artisan vendor:publish --tag=larastarter-enums
php artisan migrate

The migrations create a roles table, add a role_id foreign key to users, and seed a super admin user. The enums publish Role and OrderDirection to app/Enums/ for you to customize.

Middleware

The following middleware are registered automatically on every request:

MiddlewareWhat it does
SanitizeRequestParamsConverts "undefined", "null", "nan" string values to null
SetClientLocaleSets app locale from the X-Client-Locale request header
SetClientTimezoneSets client timezone from the X-Client-Timezone request header

The following middleware are available as route aliases:

AliasMiddlewareWhat it does
roleEnsureUserHasRoleRestricts route access to users with specific roles
content-securityContentSecurityAdds CSP and Permissions-Policy headers with Vite nonce support
// Example usage
Route::middleware('role:admin,super-admin')->group(function () {
    // ...
});

Route::middleware('content-security')->group(function () {
    // ...
});

Custom Role Enum

By default, the package uses its built-in Itcentar\Larastarter\Enums\Role enum with SUPER_ADMIN and ADMIN roles. To define your own roles:

1. Publish the config:

php artisan vendor:publish --tag=larastarter-config

2. Create your own Role enum:

<?php

namespace App\Enums;

use Itcentar\Larastarter\Traits\Core\HasEnumHelpers;

enum Role: int
{
    use HasEnumHelpers;

    case SUPER_ADMIN = 1;
    case ADMIN = 2;
    case USER = 3;

    public function slug(): string
    {
        return match ($this) {
            Role::SUPER_ADMIN => 'super-admin',
            Role::ADMIN => 'admin',
            Role::USER => 'user',
        };
    }

    public static function fromSlug(string $slug): self
    {
        return match ($slug) {
            'super-admin' => Role::SUPER_ADMIN,
            'admin' => Role::ADMIN,
            'user' => Role::USER,
        };
    }
}

3. Update the config:

// config/larastarter.php

return [
    'role_enum' => \App\Enums\Role::class,
];

Your custom enum must be an int-backed BackedEnum with slug() and fromSlug() methods.

Publish Tags

TagDestinationDescription
larastarter-migrationsdatabase/migrations/Roles & user migrations
larastarter-enumsapp/Enums/Enum stubs (Role, OrderDirection)
larastarter-configconfig/Package configuration
larastarter-traitsapp/Traits/All traits
larastarter-traits-coreapp/Traits/Core/AsAction, HasEnumHelpers, WorksWithFiles, Mediable
larastarter-traits-modelapp/Traits/Model/Filterable, HasSoftDeletes, CascadeSoftDeletes, HasFileFields, Loggable, Togglable, IsTimezoneAware, WithinCompany, HasPriorityOrdering, HasAttributeDefaults, HasRole
larastarter-traits-formrequestapp/Traits/FormRequest/WorksWithFormData
larastarter-traits-excelapp/Traits/Excel/HasGeneratedFilename, LongNumbersToStringCell
larastarter-exceptionsapp/Exceptions/Exception classes
larastarter-classesapp/Classes/Base classes (LocalizedFormRequest, TimezoneAwareResource)
larastarter-middlewareapp/Http/Middleware/HTTP middleware
larastarter-scopesapp/Models/Scopes/Model scopes
larastarter-actionsapp/Actions/Action classes
larastarter-helpersapp/Helper functions

To publish everything at once:

php artisan vendor:publish --provider="Itcentar\Larastarter\LarastarterServiceProvider"

Optional Dependencies

PackageRequired for
spatie/laravel-activitylogLoggable trait
maatwebsite/excelHasGeneratedFilename trait
phpoffice/phpspreadsheetLongNumbersToStringCell trait

License

MIT