Download the PHP package fullsmack/laravel-slice without Composer
On this page you can find all versions of the php package fullsmack/laravel-slice. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download fullsmack/laravel-slice
More information about fullsmack/laravel-slice
Files in fullsmack/laravel-slice
Package laravel-slice
Short Description A simple modules or slice package for Laravel
License MIT
Homepage https://github.com/fullsmack/laravel-slice
Informations about the package laravel-slice
Laravel Slice
Modular architecture for Laravel applications — organize your app into standalone "slices" that keep related code together (routes, views, translations, migrations, commands, config).
It can be used to structure modules, vertical slices, horizontal UI-slices, and other standalone or portable features.
Overview
- Purpose: Provide a lightweight convention to compose self-contained modules (slices) with a consistent namespace and resource resolution.
- Main idea: each slice registers a namespace
slice-name::used for config, translations and views so everything related to the slice stays with the module.
Installation
Project Structure
Laravel Slice expects your application to be organized with slices in a dedicated folder (by default src/). This works alongside Laravel's default app/ folder:
Configuration
The package can be configured by publishing the config file:
This creates config/laravel-slice.php where you can customize:
root.folder: The folder name where slices are stored (default:'src')root.namespace: The root namespace for slices (default:'slice')discovery.type: Service provider discovery method (default:'composer')
Service Provider Registration
Slices can be auto-discovered or manually registered:
Auto-Discovery (Default)
When discovery.type is set to 'composer' (default), slice service providers are automatically registered in your composer.json:
The make:slice command automatically adds new slices to this list.
Manual Registration
To disable auto-discovery, set discovery.type to any other value (e.g., 'manual'). Then register slice service providers manually in your config/app.php:
Quick Start
Make a slice by running the following command:
This scaffolds a slice with the full directory structure and adds a service provider to configure the slice. You need to make your own configurations in the service provider's configure() method:
Slice Structure
Slices are organized within your configured root folder (default: src/). Typical slice layout:
Configuring a Slice
Sliceis the configuration object you receive inconfigure(Slice $slice).- Common fluent methods:
setName(),useViews(),useTranslations(),useMigrations(),useRoutes(),withCommands(),withExtension(),withConnection().
Short example (minimal):
Custom Extensions
Extensions provide an extensibility mechanism for slices, allowing you to add custom functionality that integrates with the slice lifecycle. Extensions can be implemented by other packages or created directly in your application.
Creating an Extension
Implement the Extension interface:
Registering Extensions
Add extensions to your slice configuration:
Namespacing & Resources
-
Every slice registers a namespace
slice-name::automatically. Use this namespace for config, translations and views: - Config registration is automatic: you do not need to explicitly register slice config files inside
configure()in order forslice-name::config resolution to work.
Commands & Scaffolding
Available scaffold and slice commands (located under src/Command):
MakeSlice— scaffold a new sliceMakeComponent— create a UI component inside a sliceMakeMigration— generate a slice migration (--slice=NAMEflag)MakeTest— scaffold slice testsMigrateSlice— run migrations for a specific sliceSliceDefinitions— helpers for slice path/namespace logic in commands
Common usage examples:
Migrations & Connections
- Slices can optionally use a dedicated database connection. The slice works with the app default connection when no slice connection is configured.
withConnection()onSlicecontrols connection resolution. Resolution order:- Explicit argument passed to
withConnection('name') - Config value from
{sliceName}::database.defaultwhenwithConnection()is called without an argument - Application default connection when
withConnection()is not used
- Explicit argument passed to
UsesConnectiontrait: models can opt in to be bound to slice connections.SliceMigrationtrait: migrations generated for slices will use the slice connection when present and provide aschema()helper bound to that connection.
Connection example:
If you want to bind the models to the connection at the slice configuration level:
Testing
- Use
RefreshSliceDatabase(testing helper) to run and refresh migrations for slice-specific connections and to wrap tests in transactions. Typical usage:
Gotchas & Notes
- The namespace
slice-name::is the canonical way to reference a slice's resources (config, views, translations). - Config files placed under a slice's
config/directory are auto-registered and available viaconfig('slice::key')— you don't need to call a registration helper inconfigure()to make them available. - Models with a dedicated connection must use
UsesConnectiontrait for automatic connection binding viawithConnection().
Contributing
- See tests under tests/ for examples of package integration and behavior.