mrshanebarron/slider
A Laravel package for adding configurable sliders to your application. It helps define and manage slider items and render them in Blade views, offering a lightweight way to build carousels or content sliders without a heavy frontend dependency.
composer require mrshanebarron/slider — on Laravel 5.5+ the service provider is auto-registered. Only touch config/app.php if you're on an old skeleton or need to reorder providers.vendor:publish (which will drag in unrelated vendor files):
php artisan vendor:publish --tag=sb-config
php artisan vendor:publish --tag=sb-assets
php artisan vendor:publish --tag=sb-views # only if you intend to override markup
Check the package README for the exact tag names before running — the sb- prefix applies to the config file, and tags usually follow suit.env() the package reads is in there, so it doubles as your .env.example checklist.php artisan storage:link if it's the public disk, and verify with a hardcoded path before wiring uploads.--tag=sb-migrations then php artisan migrate). If not, you own the schema — create the model/table yourself and match the column names the package's renderer expects (image, title, caption, link, sort/position, visibility flag). Getting these column names right on day one prevents the most common "slider renders empty" report.First use case: seed two or three rows, drop the package's Blade component/include into one existing layout, and confirm images render in the right order. That single end-to-end path proves the config, the disk, the schema, and the asset publish are all correct — in that order of likelihood of being wrong.
Group your sliders from day one. A hero banner and a sidebar carousel are different content, and retrofitting a group/key column later means a data migration. Add it to the table before you have real content, then render with the group as an argument.
Ordering is a write-path problem, not a read-path one. Store an integer sort column with a unique-per-group index, and implement drag-reorder as a single transactional batch update (lockForUpdate, then rewrite positions 1..n). Do not let admins type arbitrary numbers into a text field — you'll get duplicates and gaps that make the read query ambiguous. Read with orderBy('sort') and keep the tiebreaker explicit (->orderBy('id')) so results are deterministic in tests.
Scope visibility in the model, not the view. Put active() and scheduled() (published_at window) scopes on the slide model and always start the slider query from them. Views should never contain @if ($slide->is_active) — that's how inactive slides leak into production.
Cache the query, bust it on write. Sliders render on the highest-traffic page in the app, which makes them a prime N+1/cache target. Cache::remember("slider.{$group}", ...) around the collection, and forget it from a model saved/deleted observer plus on reorder. Key the cache on the group, not the route — the same slider usually appears in several places.
Isolate the frontend asset. Published vendor JS is global by default. Wrap script inclusion in @once (or @push('scripts')) so it only loads on pages that actually render a slider, and pin the published asset filename in your deploy so a re-publish doesn't silently swap versions under a browser cache.
Make images render-ready at upload time. Store one canonical upload and generate the exact dimensions the config expects (plus a 2x), rather than letting the Blade view scale a 4000px JPEG. This is also where you enforce alt text — see gotchas.
Testing. Use RefreshDatabase and a slide factory; assert the rendered HTML contains images in the expected order and that inactive slides are absent. Override slider options with config(['sb-slider.autoplay' => false]) inside the test rather than editing the config file.
Deployment order: composer install → publish/migrate (first deploy only) → php artisan storage:link (first deploy only) → php artisan view:clear if you've overridden views → php artisan config:cache last.
sb- prefix is a moving target. v1.0.1 only fixed the config filename. If you installed earlier, your published file still has the old name, and Laravel won't overwrite it without --force. After upgrading, run ls config | grep sb- and confirm exactly one slider config exists — a stale duplicate means mergeConfigFrom() silently wins with defaults.--force clobbers customisations. Before re-publishing to pick up new config keys, copy config/sb-slider.php aside or diff it against vendor/mrshanebarron/slider/config/. The same applies to published views and assets.local, log-with-context elsewhere) so misconfiguration surfaces at deploy time.5 that means 5ms produces an unusable flicker. Read the config's comments before setting a value, and test on a real page, not in a unit test.php artisan config:clear after any .env change locally; on production always finish with config:cache again. And never call env() in your own providers or view composers — it returns null under cached config.width/height (or an aspect-ratio wrapper) on the image tag; otherwise the slider causes a CLS hit on your best-performing page.alt text at the model/admin layer, ensure the slider doesn't autoplay under prefers-reduced-motion, and verify arrow controls are keyboard-focusable. Vendor sliders rarely ship this and audits will find it.SoftDeletes, a "deleted" slide disappears from the admin list but may still satisfy your active() scope depending on whether the global scope is applied in the package's query. Check the SQL with ->toSql() once rather than guessing."^1.0" is sensible; avoid * until you've seen a minor release land without a filename or key change.How can I help you explore Laravel packages today?