PHP code example of igorsgm / laravel-ghost

1. Go to this page and download the library: Download igorsgm/laravel-ghost 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/ */

    

igorsgm / laravel-ghost example snippets


// Using the Facade (recommended), which will take the variables from the ghost.php config file
$contentApi = Ghost::content();
$response = $contentApi->posts()->all();

// Or you can set the variables manually
$contentApi = Ghost::content([
    'key' => '22444f78447824223cefc48062',
    'domain' => 'https://demo.ghost.io',
    'version' => 4
]);

$response = $contentApi->posts()->all();
$posts = $response->data;
$meta = $response->meta;

// All resources returned as SuccessResponse (or ErrorResponse)
Ghost::content()->posts()->all();
Ghost::content()->authors()->all();
Ghost::content()->tags()->all();
Ghost::content()->pages()->all();
Ghost::content()->settings()->all();
Ghost::content()->tiers()->all();

// Retrieve a single resource by slug
Ghost::content()->posts()->fromSlug('welcome');

// Retrieve first resource item
Ghost::content()->posts()->first();

// Retrieve a single resource by id
Ghost::content()->posts()->find('6285dbba44c5d85187a074ba');

// Get paginated resources
Ghost::content()->posts()->paginate();
$response = Ghost::content()->posts()->paginate(15);

$posts = $response->data;
$meta = $response->meta;

// Browse between pages
$response->getNextPage();
$response->getPreviousPage();

Ghost::content()->posts()
    ->html') // https://ghost.org/docs/content-api/#fields
    ->formats('html') // https://ghost.org/docs/content-api/#formats
    ->filter('author:john+featured:true') // https://ghost.org/docs/content-api/#filtering
    ->limit(20) // https://ghost.org/docs/content-api/#limit
    ->page(2) // https://ghost.org/docs/content-api/#page
    ->orderBy('title', 'DESC') // https://ghost.org/docs/content-api/#order
    ->get();

// Create post with mobiledoc source
Ghost::admin()->posts()->create([
    'title' => 'My Test Post',
    'mobiledoc' => '{"version":"0.3.1","atoms":[],"cards":[],"markups":[],"sections":[[1,"p",[[0,[],0,"My post content. Work in progress..."]]]]}',
    'status' => 'published',
]);

// Create post with HTML source
Ghost::admin()->posts()->source('html')->create([
    'title' => 'My Test Post 2',
    'html' => '<p>My post content. Work in progress...</p>',
    'status' => 'published',
]);

// Update resource with mobiledoc source
// The updated_at field is 

// Upload image
$imagePathOrUrl = 'https://picsum.photos/200';
$response = Ghost::admin()->images()->upload($imagePathOrUrl);

// Upload theme (.zip)
$zipPathOrUrl = 'https://www.learningcontainer.com/wp-content/uploads/2020/05/sample-zip-file.zip';
$response = Ghost::admin()->themes()->upload($zipPathOrUrl);

// Activate a theme
Ghost::admin()->themes()->activate('theme-name');
bash
php artisan vendor:publish --provider="Igorsgm\Ghost\GhostServiceProvider" --tag="ghost-config"