Laravel Testimonial
A Laravel package for managing testimonials with translatable content
#Laravel Testimonial
A Laravel package for managing testimonials, with translatable content powered by spatie/laravel-translatable.
#Features
- Testimonials — Name, role, company, avatar, rating (1-5), order, and active flag
- Translatable Content — Testimonial content is 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
testimonialstable 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-testimonial
Publish and run the migrations:
php artisan vendor:publish --tag="testimonial-migrations" php artisan migrate
Publish the config file (optional):
php artisan vendor:publish --tag="testimonial-config"
#Configuration
The config file (config/testimonial.php) covers:
#Table Names
'table_names' => [ 'testimonials' => 'testimonials', ],
#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
#Testimonials
use JeffersonGoncalves\Testimonial\Models\Testimonial; $testimonial = Testimonial::create([ 'name' => 'Jane Cooper', 'role' => 'CEO', 'company' => 'Acme Inc.', 'avatar' => 'avatars/jane-cooper.jpg', 'content' => ['en' => 'This product changed how we work.', 'pt_BR' => 'Este produto mudou a forma como trabalhamos.'], 'rating' => 5, 'order' => 1, 'is_active' => true, ]); $testimonial->content; // resolved for the current app locale, with fallback
Only content is translatable — name, role, company, and avatar are plain strings.
#Scopes
Testimonial::active()->ordered()->get();
#Translations
Because the model uses Spatie\Translatable\HasTranslations, the full spatie/laravel-translatable API is available:
$testimonial->getTranslation('content', 'pt_BR'); $testimonial->setTranslation('content', 'pt_BR', 'Recomendo muito!'); $testimonial->getTranslations('content'); // ['en' => '...', 'pt_BR' => '...'] $testimonial->translate('content', '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.