jeffersongoncalves / laravel-how-it-works
A Laravel package for managing 'how it works' steps with translatable titles and descriptions
Package info
github.com/jeffersongoncalves/laravel-how-it-works
pkg:composer/jeffersongoncalves/laravel-how-it-works
Fund package maintenance!
Requires
- php: ^8.2
- illuminate/contracts: ^12.0|^13.0
- illuminate/database: ^12.0|^13.0
- illuminate/support: ^12.0|^13.0
- spatie/laravel-package-tools: ^1.15
- spatie/laravel-translatable: ^6.11
Requires (Dev)
- larastan/larastan: ^2.9|^3.0
- laravel/pint: ^1.0
- nunomaduro/collision: ^8.0
- orchestra/testbench: ^10.0|^11.0
- pestphp/pest: ^3.0|^4.0
- pestphp/pest-plugin-laravel: ^3.0|^4.0
README
Laravel How It Works
A Laravel package for managing an ordered list of "how it works" steps — icon + translatable title/description — for landing-page style sections, powered by spatie/laravel-translatable.
Features
- Steps — Icon, title, description, order, and active flag for each step
- Translatable Content — Titles and descriptions are translatable via
spatie/laravel-translatable, with automatic fallback to the app's fallback locale - Ordering & Activation —
ordered()andactive()query scopes - Configurable Table Name — Override the
how_it_works_stepstable name via config - Configurable Locales — Mirrors
app.available_locales(or the app locale) to describe supported translation locales
Requirements
- PHP 8.2+
- Laravel 12.x or 13.x
Installation
You can install the package via composer:
composer require jeffersongoncalves/laravel-how-it-works
Publish and run the migrations:
php artisan vendor:publish --tag="how-it-works-migrations"
php artisan migrate
Publish the config file (optional):
php artisan vendor:publish --tag="how-it-works-config"
Configuration
The config file (config/how-it-works.php) covers:
Table Names
'table_names' => [ 'steps' => 'how_it_works_steps', ],
Locales
'locales' => config('app.available_locales') ? array_keys(config('app.available_locales')) : [config('app.locale', 'en')],
Reads from app.available_locales (an array keyed by locale code, e.g. ['en' => 'English', 'pt_BR' => 'Português']) when present, otherwise falls back to the app's default locale. The package also configures spatie/laravel-translatable's fallback behavior on boot, so a missing translation for the current locale falls back to app.fallback_locale (or any available locale if that is also missing).
Usage
use JeffersonGoncalves\HowItWorks\Models\Step; $step = Step::create([ 'icon' => 'heroicon-o-user-plus', 'title' => ['en' => 'Create an account', 'pt_BR' => 'Crie uma conta'], 'description' => ['en' => 'Sign up in seconds.', 'pt_BR' => 'Cadastre-se em segundos.'], 'order' => 1, 'is_active' => true, ]); $step->title; // resolved for the current app locale, with fallback
Scopes
Step::active()->ordered()->get();
Translations
Because the model uses Spatie\Translatable\HasTranslations, the full spatie/laravel-translatable API is available:
$step->getTranslation('title', 'pt_BR'); $step->setTranslation('title', 'pt_BR', 'Crie uma conta'); $step->getTranslations('title'); // ['en' => '...', 'pt_BR' => '...'] $step->translate('title', 'pt_BR');
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.
