BLOG // May 1, 2021
Laravel-Strapi package released
It makes listing, fetching, sorting, and caching Strapi CMS content extremely easy in Laravel. I've included some examples below:
// Instantiate the class $strapi = new Dbfx\LaravelStrapi(); // Fetch all blogs $blogs = $strapi->collection('blogs'); // Fetch a single blog ID 1 $entry = $strapi->entry('blogs', 1); // Return just the ['content'] field from the homepage array $homepageItem = $strapi->single('homepage', 'content'); // Fetch any blog posts with the slug `test-blog-post` $post = $strapi->entriesByField('blogs', 'slug', 'test-blog-post');
If you'd like to contribute please feel free to create a pull request on GitHub. Otherwise you can install it on Laravel 7 or 8 as follows:
composer require dbfx/laravel-strapi php artisan vendor:publish --tag="strapi-config"
Then add the following to your .env file:
The STRAPI_URL is the base path to your Strapi installation (often on port 1337 so add that if needed). Should you wish to run it more securely, check Strapi with SSL and Nginx.
The STRAPI_CACHE_TIME is the time in seconds to cache Strapi results locally - important for performance.
Enjoy it, and please contribute or log any issues on the Github!
Subscribe to new articles
If you enjoy my content, consider subscribing. You will only receive new blog stories, no other email.