Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Nitro Laravel Laravel Package

flyo/nitro-laravel

Seamlessly connect your Laravel application to Flyo Nitro. This package provides configuration, service bindings, and convenient helpers for fetching and rendering Nitro content, so you can build fast, content-driven sites with familiar Laravel tooling.

View on GitHub
Deep Wiki
Context7

Getting Started

Install the module through Composer and publish its configuration:

composer require flyo/nitro-laravel
php artisan vendor:publish --tag=nitro-config

Set the credentials the module reads at boot — typically a project/space token plus an optional API base URL and cache TTL:

NITRO_TOKEN=your-project-token
NITRO_API_URL=https://nitro.flyo.cloud
NITRO_CACHE_TTL=300

Look here first:

  1. config/nitro.php — token, endpoint, cache store, and any enabled features. This is the file you will touch most.
  2. The package's NitroServiceProvider — it shows what is bound into the container (the API client, the facade alias, any middleware).
  3. The README's facade/helper section — the package is small and low-traffic, so method names can shift between releases. Confirm the fetch API against the installed version's source (vendor/flyo/nitro-laravel/src) rather than trusting blog posts.

First use case — render a CMS page through a catch-all route. The module's core value is letting Flyo own the page tree while Laravel owns routing and rendering:

// routes/web.php
Route::get('/{slug?}', PageController::class)
    ->where('slug', '.*')
    ->name('nitro.page');
// app/Http/Controllers/PageController.php
public function __invoke(Request $request, string $slug = '/')
{
    $page = Nitro::page($slug, locale: app()->getLocale());

    abort_if($page === null, 404);

    return view('page', ['page' => $page]);
}

That gives you a working site in one route. Everything below builds on it.

Implementation Patterns

Catch-all controller, not catch-all middleware. A single invokable controller keeps the fetch, the 404 policy, and the view selection in one obvious place. Reserve middleware for cross-cutting concerns (locale resolution, redirects, injection of navigation data) so the controller stays testable.

Render blocks, don't echo HTML. Nitro returns structured blocks. Map each block type to a Blade component and loop over them — this is the pattern that scales:

@foreach ($page->blocks as $block)
    <x-dynamic-component :component="'nitro.'.$block->type" :block="$block" />
@endforeach

Keep a default/fallback component for unknown types so a new block type in the CMS doesn't break the site on deploy day.

Cache at the fetch boundary, keyed by everything that varies. The client call is the slow, failure-prone part. Cache the hydrated object, and make the key explicit about locale, draft state, and slug:

$key = "nitro:page:{$locale}:{$slug}:".($draft ? 'draft' : 'live');

return Cache::remember($key, config('nitro.cache_ttl'), fn () => Nitro::page($slug, $locale, $draft));

If you use taggable stores, tag by content type so you can flush navigation and pages independently when editors publish.

Resolve navigation once per request. Navs are requested on nearly every page. Fetch them in a view composer or a scoped singleton binding, and cache them with the same TTL strategy — never fetch the menu inside a Blade loop.

Draft/preview mode via signed URLs. Expose preview through a signed route so only editors with a valid Flyo-generated link bypass the cache:

Route::get('/preview/{slug}', PreviewController::class)
    ->middleware('signed')
    ->where('slug', '.*');

Pass draft: true to the client, skip the cache, add X-Robots-Tag: noindex, and never let the draft flag leak into shared cache keys.

Localization as an explicit argument. Resolve the locale from route prefix, Accept-Language, or a session preference — but pass it down explicitly. Avoid reading app()->getLocale() deep inside the client, or you'll get cache collisions when the locale changes mid-request (queues, console commands, tests).

Fail soft on API outages. Wrap fetches in a try/catch on the transport exception, then serve a cached copy if available, or a friendly 503/placeholder. A CMS API hiccup should not take down a marketing site's homepage.

Fake the client in tests. Bind a stub implementation of the client contract into the container and return fixture payloads. This keeps tests fast and, more importantly, makes the package's payload shape part of your own test suite — valuable when the upstream package is low-traffic and changes rarely get documented.

Gotchas and Tips

  • The token is server-side only. Never pass it to a browser context, Inertia prop, or Blade @json block. Treat preview tokens as scoped, short-lived credentials; if a preview link leaks, rotate.
  • Cache keys are the #1 source of "why is the wrong language showing?" bugs. Locale, draft flag, and slug all have to be in the key. Add a schema/version prefix so a payload-breaking upgrade invalidates old entries automatically.
  • Route ordering matters with a catch-all. Register /admin, /api, health checks, and asset routes before the {slug} route. On Apache/Nginx, also confirm the web server doesn't serve stale static files ahead of Laravel.
  • Guard against schema drift. Access blocks and fields defensively ($block->type ?? 'unknown', null-safe property access). A missing CMS field should degrade gracefully, not throw a 500 on every page.
  • Sanitize rich text. If any block returns HTML, run it through a purifier before {!! !!}. Trusting CMS HTML is fine until an editor pastes something from a compromised source.
  • Low release cadence cuts both ways. One star and few dependents means fewer eyes on breaking changes. Pin the version ("flyo/nitro-laravel": "^1.0" with a tested lockfile), read CHANGELOG.md before upgrading, and skim the diff — the surface is small enough to review in minutes.
  • Debugging API issues: enable the package's debug/logging flag (check config/nitro.php) in local, log the raw response body on transport errors in staging, and use php artisan tinker to call the client directly and inspect the payload shape before writing view code.
  • Extension points worth knowing: override the published config, rebind the client binding in your own provider, and add custom block components under a nitro. namespace. Because the service provider is registered by package discovery, you can also dont-discover it and register manually if you need to control binding order relative to your own providers.
  • Keep content fetch logic out of models and jobs. If you need Nitro data in a queue worker or console command, call the client there directly and set the locale explicitly — request-scoped assumptions (session locale, request cache) won't exist in those contexts.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
adachsoft/changelog-linter
adachsoft/collection
payerurl/telegrambot-crypto-payment-instant-payout
dskripchenko/laravel-hybrid-search
riorizkyrainey/lara-ced
mehedimi/static-vel
zharp/zharp
nonsapiens/bigquery-model-sync
lgu-bayambang-ict-office/lgu-laravel-development-standards
andydefer/laravel-support
se7enxweb/flysystem
lampwick/laravel
jeslage/statamic-emojis
micahdshackelford/rmap-laravel
draftsmaninc/draftsman
square-bit/laravel-volition
himito/laravel-mailman
htinlynn/genius-helper
maco-studios/hephaestus
adachsoft/php-code-style