A Laravel package to integrate with Strapi CMS, providing an elegant way to interact with Strapi models and components.
You can install the package via Composer:
composer require aw-studio/laravel-strapi
After installation, publish the configuration file:
php artisan vendor:publish --tag=laravel-strapi-config
Then, add the following environment variables to your .env
file:
STRAPI_BASE_URL=https://your-strapi-url.com
STRAPI_CACHE_ACTIVE=true # Set to false to disable caching
STRAPI_CACHE_TTL=3600 # Cache duration in seconds
You can create Strapi models using the following command:
php artisan make:strapi-model {name}
This will create a SingleType or CollectionType model in App\Strapi\Models
.
You can query models fluently:
$post = Post::locale('de')
->where('Slug', $slug)
->populate([
'Image' => [
'populate' => '*',
],
])
->first();
You can create Strapi components with the following command:
php artisan make:strapi-component {name?}
Each component represents a Strapi component (e.g., from dynamic zones). It consists of:
- A class file:
App\Strapi\Components\<CollectionName>\ComponentName.php
- A corresponding Blade view file
Components must be registered in the config/laravel-strapi.php
configuration file.
You can populate all components of a Content dynamic zone like this:
$post = Post::locale('de')
->where('Slug', $slug)
->populateContent()
->first();
You can render dynamic zone components in Blade templates using the x-dynamiczone
component:
<x-dynamiczone :items="$page->Content" />
This package is open-sourced software licensed under the MIT license.