Database-Endpoint Examples

Query Database

use Illuminate\Support\Collection;
use FiveamCode\LaravelNotionApi\Query\Filter;
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("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"]
            ]
        )
    );

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