PHP code example of yugo / blogger

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

    

yugo / blogger example snippets


$blog = Blogger::blog();


// retrieving posts
$posts = Blogger::posts($blog['id']);
$posts = Blogger::search($keyword, $blogId);
$post = Blogger::postById($postId, $blogId);
$post = Blogger::postByPath($path, $blogId);

// retrieving pages
$pages = Blogger::pages($blog['id']);
$page = Blogger::page($pageId, $blogId);

$posts = Blogger::withImages()->posts();



namespace App\Http\Controllers;

use Illuminate\Http\JsonResponse;
use Illuminate\Support\Facades\Cache;
use Illuminate\Http\Request;
use Yugo\Blogger\Facades\Blogger;

class BloggerController extends Controller
{
    /**
     * @var Blogger
     */
    private $blogger;

    public function __construct()
    {
        $blog = Cache::remember('blogger.blog', now()->addDays(7), function (){
           return Blogger::blog();
        });

        abort_if(empty($blog), 404, __('Blog not found.'));

        $this->blogger = Blogger::setBlog($blog['id']);
    }

    /**
     * @return JsonResponse
     */
    public function blog(): JsonResponse
    {
        return response()->json($this->blogger->blog());
    }

    /**
     * @return JsonResponse
     */
    public function posts(): JsonResponse
    {
        return response()->json($this->blogger->posts());
    }

    /**
     * @param string $id
     * @return JsonResponse
     */
    public function post(string $id): JsonResponse
    {
        return response()->json($this->blogger->postById($id));
    }

    /**
     * @param string $id
     * @return JsonResponse
     */
    public function comments(string $id): JsonResponse
    {
        return response()->json($this->blogger->comments($id));
    }

    /**
     * @param string $post
     * @param string $comment
     * @return JsonResponse
     */
    public function comment(string $post, string $comment): JsonResponse
    {
        return response()->json($this->blogger->comment($comment, $post));
    }

    /**
     * @param Request $request
     * @return JsonResponse
     */
    public function search(Request $request): JsonResponse
    {
        $this->validate($request, [
            'keyword' => ['

Route::get('blogger/blog', 'BloggerController@blog');
Route::get('blogger/posts', 'BloggerController@posts');
Route::get('blogger/post/{id}', 'BloggerController@post');
Route::get('blogger/post/{id}/comments', 'BloggerController@comments');
Route::get('blogger/post/{post}/comment/{comment}', 'BloggerController@comments');
Route::get('blogger/search', 'BloggerController@search');
Route::get('blogger/pages', 'BloggerController@pages');
Route::get('blogger/page/{id}', 'BloggerController@page');