PHP code example of kamil-malinski / laravel-strapi

1. Go to this page and download the library: Download kamil-malinski/laravel-strapi library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

kamil-malinski / laravel-strapi example snippets


use KamilMalinski\LaravelStrapi\LaravelStrapi;

$strapi = new LaravelStrapi();
$blogs = $strapi->collection('blogs');
$entry = $strapi->entry('blogs', 1);

use KamilMalinski\LaravelStrapi\LaravelStrapi;

$strapi = new LaravelStrapi();
$blogs = $strapi->collection('blogs', $sortKey = 'id', $sortOrder = 'DESC', $limit = 20, $start = 0, $fullUrls = true);

$entry = $strapi->entry('blogs', 1, $fullUrls = true);

use KamilMalinski\LaravelStrapi\LaravelStrapi;

$strapi = new LaravelStrapi();

// Fetch the full homepage array
$homepageArray = $strapi->single('homepage');

// Return just the ['content'] field from the homepage array
$homepageItem = $strapi->single('homepage', 'content');

use KamilMalinski\LaravelStrapi\LaravelStrapi;

$strapi = new LaravelStrapi();

$entries = $strapi->entriesByField('blogs', 'slug', 'test-blog-post');

use KamilMalinski\LaravelStrapi\LaravelStrapi;

$strapi = new LaravelStrapi();

// load all relations one Level deep 
$homepageArray = $strapi->populate(['*'])->single('homepage');

// 2 Level or deeper example
$homepageArray = $strapi->populate(['homepage.navbar.links', 'homepage.metadata'])->single('homepage');

use KamilMalinski\LaravelStrapi\LaravelStrapi;

$strapi = new LaravelStrapi();

$query = [
    'populate' => [
        'testDZ' => [
            'populate' => '*'
        ],
    ]
];

$homepageArray = $strapi->query($query)->single('articels');

$query = [
    'fields' => ['title', 'slug'],
    'populate' => [
        'headerImage' => [
            'fields' => ['name', 'url']
        ],
    ]
];

$homepageArray = $strapi->query($query)->single('articels');

bash
php artisan vendor:publish --provider="KamilMalinski\LaravelStrapi\LaravelStrapiServiceProvider" --tag="strapi-config"
$start