PHP code example of fiveam-code / laravel-notion-api

1. Go to this page and download the library: Download fiveam-code/laravel-notion-api 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/ */

    

fiveam-code / laravel-notion-api example snippets


   use \Notion;

   Notion::databases()->find("8284f3ff77e24d4a939d19459e4d6bdc");
   

use \Notion;

Notion::databases()
        ->find("8284f3ff77e24d4a939d19459e4d6bdc");

Notion::pages()
        ->find("e7e5e47d-23ca-463b-9750-eb07ca7115e4");

Notion::search("Search term")
        ->query()
        ->asCollection();

use FiveamCode\LaravelNotionApi\Query\Filters\Filter;
use FiveamCode\LaravelNotionApi\Query\Filters\Operators;

$nameFilter = Filter::textFilter('Name', Operators::EQUALS, 'Ada Lovelace');

\Notion::database("8284f3ff77e24d4a939d19459e4d6bdc")
    ->filterBy($nameFilter)
    ->limit(5)
    ->query()
    ->asCollection();

use Illuminate\Support\Collection;
use FiveamCode\LaravelNotionApi\Query\Filters\Filter;
use FiveamCode\LaravelNotionApi\Query\Filters\FilterBag;
use FiveamCode\LaravelNotionApi\Query\Filters\Operators;
use FiveamCode\LaravelNotionApi\Query\Sorting;

# Give me all entries that are
# (KnownFor == UNIVAC || KnownFor == ENIAC)
# and sort them by name ascending

$filterBag = new FilterBag(Operators::AND);

$filterBag->addFilter(
    Filter::rawFilter("Known for", [
        "multi_select" => [Operators::CONTAINS => "UNIVAC"],
    ])
);

$filterBag->addFilter(
    Filter::rawFilter("Known for", [
        "multi_select" => [Operators::CONTAINS => "ENIAC"],
    ])
);

\Notion::database("8284f3ff77e24d4a939d19459e4d6bdc")
    ->filterBy($filterBag)
    ->sortBy(Sorting::propertySort('Name', 'ascending'))
    ->limit(5)
    ->query()
    ->asCollection();