承接 svnwa/laravel-strapi 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

svnwa/laravel-strapi

最新稳定版本:v1.2

Composer 安装命令:

composer require svnwa/laravel-strapi

包简介

This package provides an implementation to consume the Strapi REST API.

README 文档

README

Latest Version on Packagist Total Downloads

This package provides an implementation to consume the Strapi REST API.

The current implementation only supports fetching data from Strapi since I personally didn't have a use case to write data to it via API yet.

Currently supports Strapi v4 which is a bit different from the preceding v3 REST API.

Installation

1. Installation via Composer
composer require svnwa/laravel-strapi
2. Publishing the the config file:
php artisan vendor:publish --provider="svnwa\laravel-strapi\LaravelStrapiServiceProvider" --tag="laravel-strapi"
3. Editing the the .env file:

The STRAPI_CACHE_STORAGE_TIME is optional.1

The default value is defined in the config file at 3600 seconds (1 hour).
STRAPI_API_TOKEN=some_strapi_api_token
STRAPI_BASE_URL="https://somestrapiurl.com"
STRAPI_CACHE_STORAGE_TIME=3600
4. Optional "cache reset" route

This package also provides an optional route to automatically reset the cache with a Webhook from within Strapi e.g. after update or creation of a resource. The route can be activated in the config file. Just set the value to true:

'cacheResetRoute' => true

Usage

This package attemps to make use of a fluent api similar to Laravels Eloquent:

use Svnwa\LaravelStrapi\Facades\Strapi;

$listOfRestaurants = Strapi::collection('restaurants')
    ->paginate(0,20,true)
    ->fields(['name','adress','tel'])
    ->sortBy([
            ['name','asc'],
        ]
    ->filterBy([
            ['[name][$contains]','pizza'],
        ])
    ->populate()
    ->locale('de')
    ->withFullUrls()
    ->publicationState('preview')
    ->get();

Examples

  1. Get a list of entries

  2. Get an entry

  3. Parameters

  • Get a list of entries

GET api/restaurants

use Svnwa\LaravelStrapi\Facades\Strapi;

$listOfRestaurants = Strapi::collection('restaurants')->get();
  • Get an entry

GET api/restaurants/999

use Svnwa\LaravelStrapi\Facades\Strapi;

$listOfRestaurants = Strapi::entry('restaurants',999)->get();

Using Strapis basic API Parameters:

  • sort Sorting the response

Supports Strapis sorting on one or multiple fields and/or their direction

GET api/restaurants?sort[0]=id:asc&sort[1]=name:desc

use Svnwa\LaravelStrapi\Facades\Strapi;

$listOfRestaurants = Strapi::collection('restaurants')
    ->sortBy([
        ['id','asc'],
        ['name','desc'],
    ]);
  • pagination Page through entries

Supports Strapis pagination on results by offset

GET api/restaurants?pagination[start]=0&pagination[limit]=20&pagination[withCount]=true

use Svnwa\LaravelStrapi\Facades\Strapi;

$listOfRestaurants = Strapi::collection('restaurants')
    ->paginate(0,20,true);
  • filters

Supports Strapis filter results found with its "Get entries" method

GET api/restaurants?filters[name][$contains]=pizza

use Svnwa\LaravelStrapi\Facades\Strapi;

$listOfRestaurants = Strapi::collection('restaurants')
    ->filterBy([
        ['[name][$contains]','pizza'],
    ]);
  • fields

Queries can accept a fields parameter to select only some fields.

GET api/restaurants?fields[0]=name&fields[1]=adress&fields[2]=tel

use Svnwa\LaravelStrapi\Facades\Strapi;

$listOfRestaurants = Strapi::collection('restaurants')
    ->fields(['name','adress','tel']);
  • populate

Queries can accept a populate parameter to populate various field types

Populate with wildcard. If no parameter is given to the populate() method it defauls to using the wildcard operator: GET api/restaurants?populate=*

use Svnwa\LaravelStrapi\Facades\Strapi;

$listOfRestaurants = Strapi::collection('restaurants')
    ->populate();

or:

GET api/restaurants?populate[0]=menu&populate[1]=customers

use Svnwa\LaravelStrapi\Facades\Strapi;

$listOfRestaurants = Strapi::collection('restaurants')
    ->populate(['menu','customers']);

Tip: Strapi offers deep population for e.g. nested components and does not populate them by default. Even not with the wildcard * GET api/restaurants?populate[0]=menu.images

  • publicationState

GET api/restaurants?publicationState=preview Queries can accept a publicationState parameter to fetch entries based on their publication state:

use Svnwa\LaravelStrapi\Facades\Strapi;

$listOfRestaurants = Strapi::collection('restaurants')
    ->publicationState('preview');
  • locale

The locale API parameter can be used to get entries from a specific locale

GET api/restaurants?locale=de

use Svnwa\LaravelStrapi\Facades\Strapi;

$listOfRestaurants = Strapi::collection('restaurants')
    ->locale('de');

License

MIT. Please see the license file for more information.

Footnotes

  1. Time is in seconds.

统计信息

  • 总下载量: 4.23k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 3
  • 点击次数: 3
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 3
  • Watchers: 1
  • Forks: 3
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-05-24

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固