PHP code example of elsayed85 / laravel-notion-api

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

    

elsayed85 / laravel-notion-api example snippets


use FiveamCode\LaravelNotionApi\Notion;
use Illuminate\Support\Collection;
use FiveamCode\LaravelNotionApi\Query\Sorting;
use FiveamCode\LaravelNotionApi\Query\Filter;

// Setup basic API connection
$notion = new Notion();
$notion->v1();

// Returns a specific page
$notion->pages()->find($yourPageId);

// Queries a specific database and returns a collection of pages (= database entries)
$sortings = new Collection();
$filters = new Collection();

$sortings
  ->add(Sorting::propertySort("Ordered", "ascending"));
$sortings
  ->add(Sorting::timestampSort("created_time", "ascending"));

$filters
  ->add(Filter::textFilter("title", ["contains" => "new"]));
// or
$filters
  ->add(Filter::rawFilter("Tags", ["multi_select" => ["contains" => "great"]]));
  
$notion
  ->database($yourDatabaseId)
  ->filterBy($filters) // filters are optional
  ->sortBy($sortings) // sorts are optional
  ->limit(5) // limit is optional
  ->query();