PHPackages                             fullsmack/laravel-slice - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Framework](/categories/framework)
4. /
5. fullsmack/laravel-slice

ActiveLibrary[Framework](/categories/framework)

fullsmack/laravel-slice
=======================

A simple modules or slice package for Laravel

0.3.0(4mo ago)02251MITPHPPHP ^8.3|^8.4

Since Jan 4Pushed 2mo agoCompare

[ Source](https://github.com/fullsmack/laravel-slice)[ Packagist](https://packagist.org/packages/fullsmack/laravel-slice)[ Docs](https://github.com/fullsmack/laravel-slice)[ RSS](/packages/fullsmack-laravel-slice/feed)WikiDiscussions main Synced 3w ago

READMEChangelogDependencies (4)Versions (7)Used By (1)

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**

```
composer require fullsmack/laravel-slice
```

**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:

```
your-project/
├── app/                    # Default Laravel application code
├── src/                    # Slice modules (configurable)
│   ├── pizza/
│   │   ├── config/
│   │   ├── src/
│   │   ├── routes/
│   │   └── ...
│   └── order/
│       └── ...
├── config/
├── database/
└── ...

```

**Configuration**

The package can be configured by publishing the config file:

```
php artisan vendor:publish --provider="FullSmack\LaravelSlice\LaravelSliceServiceProvider" --tag="config"
```

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)

[](#auto-discovery-default)

When `discovery.type` is set to `'composer'` (default), slice service providers are automatically registered in your `composer.json`:

```
{
    "extra": {
        "laravel": {
            "providers": [
                "Slice\\Pizza\\PizzaServiceProvider",
                "Slice\\Order\\OrderServiceProvider"
            ]
        }
    }
}
```

The `make:slice` command automatically adds new slices to this list.

### Manual Registration

[](#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`:

```
'providers' => [
    // ... other providers
    \Slice\Pizza\PizzaServiceProvider::class,
    \Slice\Order\OrderServiceProvider::class,
],
```

**Quick Start**

Make a slice by running the following command:

```
php artisan make:slice pizza
```

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:

```
use FullSmack\LaravelSlice\Slice;
use FullSmack\LaravelSlice\SliceServiceProvider;

final class PizzaServiceProvider extends SliceServiceProvider
{
    public function configure(Slice $slice): void
    {
        $slice->setName('pizza');
    }
}
```

**Slice Structure**

Slices are organized within your configured root folder (default: `src/`). Typical slice layout:

```
src/your-slice-name/
├── config/                 # slice config files (auto-registered under `slice-name::`)
├── resources/views/        # blade views, referenced as `slice-name::view.name`
├── lang/                   # translation files, referenced as `slice-name::file.key`
├── routes/                 # slice route definitions
├── database/migrations/    # slice-specific migrations
└── src/                    # PSR-4 classes for the slice

```

**Configuring a Slice**

- `Slice` is the configuration object you receive in `configure(Slice $slice)`.
- Common fluent methods: `setName()`, `useViews()`, `useTranslations()`, `useMigrations()`, `useRoutes()`, `withCommands()`, `withExtension()`, `withConnection()`.

Short example (minimal):

```
public function configure(Slice $slice): void
{
    $slice->setName('order')
        ->useRoutes()          // Load routes from routes/
        ->useViews()           // Load views from resources/views
        ->useTranslations()    // Load translations from lang/
        ->useMigrations()      // Load migrations from database/migrations
        ->withCommands([       // Register command classes
            \Slice\Order\Console\SyncOrders::class,
        ])
}
```

**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

[](#creating-an-extension)

Implement the `Extension` interface:

```
use FullSmack\LaravelSlice\Slice;
use FullSmack\LaravelSlice\Extension;

final class CustomExtension implements Extension
{
    public function register(Slice $slice): void
    {
        // Add custom functionality here
        // Access to slice configuration, paths, etc.

        // Example: Register Livewire or other frontend assets in your slice
    }
}
```

### Registering Extensions

[](#registering-extensions)

Add extensions to your slice configuration:

```
use FullSmack\LaravelSlice\Slice;
use FullSmack\LaravelSlice\SliceServiceProvider;

final class OrderServiceProvider extends SliceServiceProvider
{
    public function configure(Slice $slice): void
    {
        $slice->setName('order')
            ->withExtension(new CustomExtension())
            ->withExtension(new AnotherExtension());
    }
}
```

**Namespacing &amp; Resources**

- Every slice registers a namespace `slice-name::` automatically. Use this namespace for config, translations and views:

```
config('pizza::settings.default-timezone');
trans('pizza::messages.order-created');
view('pizza::emails.receipt');
```

- Config registration is automatic: you do not need to explicitly register slice config files inside `configure()` in order for `slice-name::` config resolution to work.

**Commands &amp; Scaffolding**

Available scaffold and slice commands (located under `src/Command`):

- `MakeSlice` — scaffold a new slice
- `MakeComponent` — create a UI component inside a slice
- `MakeMigration` — generate a slice migration (`--slice=NAME` flag)
- `MakeTest` — scaffold slice tests
- `MigrateSlice` — run migrations for a specific slice
- `SliceDefinitions` — helpers for slice path/namespace logic in commands

Common usage examples:

```
php artisan make:slice pizza
php artisan make:migration create_recipes_table --create=recipes --slice=pizza
php artisan migrate --slice=pizza
```

**Migrations &amp; Connections**

- Slices can optionally use a dedicated database connection. The slice works with the app default connection when no slice connection is configured.
- `withConnection()` on `Slice` controls connection resolution. Resolution order:
    1. Explicit argument passed to `withConnection('name')`

2. Config value from `{sliceName}::database.default` when `withConnection()` is called without an argument
3. Application default connection when `withConnection()` is not used

- `UsesConnection` trait: models can opt in to be bound to slice connections.
- `SliceMigration` trait: migrations generated for slices will use the slice connection when present and provide a `schema()` helper bound to that connection.

Connection example:

```
    $slice->setName('cookbook')
        ->useMigrations()
        ->withConnection('cookbook');
```

If you want to bind the models to the connection at the slice configuration level:

```
    $slice->setName('cookbook')
        ->useMigrations()
        ->withConnection('cookbook', [
            \Slice\Cookbook\Models\Recipe::class,
            \Slice\Cookbook\Models\Ingredient::class
        ]);
```

**Testing**

- Use `RefreshSliceDatabase` (testing helper) to run and refresh migrations for slice-specific connections and to wrap tests in transactions. Typical usage:

```
use FullSmack\LaravelSlice\Testing\RefreshSliceDatabase;

final class RecipeTest extends TestCase
{
    use RefreshSliceDatabase;

    protected function setUp(): void
    {
        parent::setUp();
        $this->refreshSlice('pizza');
    }
}
```

**Gotchas &amp; 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 via `config('slice::key')` — you don't need to call a registration helper in `configure()` to make them available.
- Models with a dedicated connection must use `UsesConnection` trait for automatic connection binding via `withConnection()`.

**Contributing**

- See tests under [tests/](tests/) for examples of package integration and behavior.

###  Health Score

40

—

FairBetter than 86% of packages

Maintenance79

Regular maintenance activity

Popularity14

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity47

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 97.9% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

148d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/c2678c763f7870ed797b86d3908611e1ac6bd10fb1489a6c16a9beb862ad79ad?d=identicon)[nicolaibaaring](/maintainers/nicolaibaaring)

---

Top Contributors

[![nicolaibaaring](https://avatars.githubusercontent.com/u/51752848?v=4)](https://github.com/nicolaibaaring "nicolaibaaring (93 commits)")[![claude](https://avatars.githubusercontent.com/u/81847?v=4)](https://github.com/claude "claude (2 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/fullsmack-laravel-slice/health.svg)

```
[![Health](https://phpackages.com/badges/fullsmack-laravel-slice/health.svg)](https://phpackages.com/packages/fullsmack-laravel-slice)
```

###  Alternatives

[laravel/octane

Supercharge your Laravel application's performance.

4.0k24.7M203](/packages/laravel-octane)[unopim/unopim

UnoPim Laravel PIM

10.3k2.2k](/packages/unopim-unopim)[code16/sharp

Laravel Content Management Framework

79062.6k7](/packages/code16-sharp)[nasirkhan/laravel-starter

A CMS like modular Laravel starter project.

1.4k2.7k](/packages/nasirkhan-laravel-starter)[ecotone/laravel

Ecotone for Laravel — CQRS, Event Sourcing, Sagas, Durable Workflows, and Outbox on top of Laravel Queue, via PHP attributes.

21313.7k3](/packages/ecotone-laravel)[codewithdennis/larament

Larament is a time-saving starter kit to quickly launch Laravel 13.x projects. It includes FilamentPHP 5.x pre-installed and configured, along with additional tools and features to streamline your development workflow.

3861.7k](/packages/codewithdennis-larament)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
