itcentar / larastarter
Reusable traits, migrations, enums, and actions for Laravel applications.
Requires
- php: ^8.1
- illuminate/support: ^10.0|^11.0|^12.0
Suggests
- maatwebsite/excel: Required for the Excel traits (HasGeneratedFilename)
- phpoffice/phpspreadsheet: Required for the LongNumbersToStringCell trait
- spatie/laravel-activitylog: Required for the Loggable trait
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:
| Middleware | What it does |
|---|---|
SanitizeRequestParams | Converts "undefined", "null", "nan" string values to null |
SetClientLocale | Sets app locale from the X-Client-Locale request header |
SetClientTimezone | Sets client timezone from the X-Client-Timezone request header |
The following middleware are available as route aliases:
| Alias | Middleware | What it does |
|---|---|---|
role | EnsureUserHasRole | Restricts route access to users with specific roles |
content-security | ContentSecurity | Adds 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
| Tag | Destination | Description |
|---|---|---|
larastarter-migrations | database/migrations/ | Roles & user migrations |
larastarter-enums | app/Enums/ | Enum stubs (Role, OrderDirection) |
larastarter-config | config/ | Package configuration |
larastarter-traits | app/Traits/ | All traits |
larastarter-traits-core | app/Traits/Core/ | AsAction, HasEnumHelpers, WorksWithFiles, Mediable |
larastarter-traits-model | app/Traits/Model/ | Filterable, HasSoftDeletes, CascadeSoftDeletes, HasFileFields, Loggable, Togglable, IsTimezoneAware, WithinCompany, HasPriorityOrdering, HasAttributeDefaults, HasRole |
larastarter-traits-formrequest | app/Traits/FormRequest/ | WorksWithFormData |
larastarter-traits-excel | app/Traits/Excel/ | HasGeneratedFilename, LongNumbersToStringCell |
larastarter-exceptions | app/Exceptions/ | Exception classes |
larastarter-classes | app/Classes/ | Base classes (LocalizedFormRequest, TimezoneAwareResource) |
larastarter-middleware | app/Http/Middleware/ | HTTP middleware |
larastarter-scopes | app/Models/Scopes/ | Model scopes |
larastarter-actions | app/Actions/ | Action classes |
larastarter-helpers | app/ | Helper functions |
To publish everything at once:
php artisan vendor:publish --provider="Itcentar\Larastarter\LarastarterServiceProvider"
Optional Dependencies
| Package | Required for |
|---|---|
spatie/laravel-activitylog | Loggable trait |
maatwebsite/excel | HasGeneratedFilename trait |
phpoffice/phpspreadsheet | LongNumbersToStringCell trait |
License
MIT