Picture of the author

Database-Endpoint Examples

Query Filters

We aim to implement each available filter object of the API with a convenient instance method. As long as the other filter types aren't implemented as dedicated methods, you can use the rawFilter like in the Query Database example below.

The following filter types are implemented so far:

Text properties

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

Valid operators: EQUALS, DOES_NOT_EQUAL, CONTAINS, DOES_NOT_CONTAIN, STARTS_WITH, ENDS_WITH, IS_EMPTY, IS_NOT_EMPTY.

Number properties

$filter = Filter::numberFilter("Birth year", Operators::GREATER_THAN_OR_EQUAL_TO, 1906);

Valid operators: EQUALS, DOES_NOT_EQUAL, GREATER_THAN, LESS_THAN, GREATER_THAN_OR_EQUAL_TO, LESS_THAN_OR_EQUAL_TO, IS_EMPTY, IS_NOT_EMPTY.

Query Database

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

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

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

$filters
    ->add(
        Filter::textFilter("Name", Operators::EQUALS, "Ada Lovelace")
    );

# or
$filters
    ->add(
        Filter::rawFilter(
            "Known for",
            [
                "multi_select" =>
                    ["contains" => "COBOL"]
            ]
        )
    );

# the whole query
Notion::database("8284f3ff77e24d4a939d19459e4d6bdc")
        ->filterBy($filters) // filters are optional
        ->sortBy($sortings) // sorts are optional
        ->limit(5) // limit is optional
        ->query()
        ->asCollection();

// Returns Ada Lovelace and Grace Hopper from our Test Database: https://www.notion.so/8284f3ff77e24d4a939d19459e4d6bdc