Retrieve parent information for Notion entities
v1.1.0ParentId and ParentType properties provide information about the parent page or block for a specific item. This metadata is available for Database, Page, Block, and Comment entities.website·Indexed 32 days ago
https://notionforlaravel.com/Documentation for the Laravel Notion API package (v1.1.0), providing tools to interact with Notion databases, pages, blocks, and comments. Includes guides on filtering, sorting, pagination, error handling with NotionException, and managing Notion users and entities.
ParentId and ParentType properties provide information about the parent page or block for a specific item. This metadata is available for Database, Page, Block, and Comment entities.FiveamCode\LaravelNotionApi\Entities\Properties namespace. Each class provides a value() method to instantiate the property with the correct structure before passing it to the page's setProperty() method.use FiveamCode\LaravelNotionApi\Entities\Properties\Text;
// 1. Create the property object
$textProperty = Text::value('This is a Text Property');
// 2. Assign it to the Notion page
$notionPage->setProperty('Text Property', $textProperty);all() function on the Notion::users() instance to retrieve all users in the connected workspace. Note that a maximum of 100 users can be fetched using this method. Results can be converted to a collection or JSON.Notion::users()
->all()
->asCollection(); // or `asJson()`You can retrieve a specific property by its title or get all properties as a collection from a Notion page. If a property type is supported by the package, it returns a specific property class (e.g., \Entities\Properties\Text); otherwise, it returns a generic \Entities\Properties\Property object containing the raw Notion API structure.
All property objects provide these general methods:
getTitle(): Returns the property title.getType(): Returns the property type.getContent(): Returns the base content (raw content if unsupported).getRawContent(): Returns the raw Notion API content.asText(): Returns the content as a string (JSON string if unsupported).$propertyName = 'Your Property Title';
// Get a specific property
$property = $page->getProperty($propertyName);
// Retrieve all properties as an Illuminate\Support\Collection
$collectionOfProperties = $page->getProperties();find() method on the Notion::users() instance to retrieve a specific user by providing their unique Notion user ID.$user = Notion::users()->find($userId);composer require fiveam-code/laravel-notion-apiappend method on a block instance. The parent block ID required for this operation is the UUID of the target Notion Page.use FiveamCode\LaravelNotionApi\Entities\Blocks\Paragraph;
// The parent block ID is the UUID of the Notion Page
$parentBlockId = 'f7a7c7f7-7f7f-7f7f-7f7f-7f7f7f7f7f7f';
// Create the block content
$newBlock = Paragraph::create("New TextBlock");
// Append the block to the page
Notion::block($parentBlockId)->append($newBlock);Notion::databases() builder. If no properties are specified, a required title property is automatically added. You can optionally configure the database title, cover image, icon, and description.// Basic creation
$databaseEntity = Notion::databases()
->build()
->createInPage('0adbc2eb47e84569a700a60d537615be');
// Creation with configuration
$databaseEntity = Notion::databases()
->build()
->title('Created By Laravel')
->coverExternal('https://example.com/cover.jpg')
->iconExternal('https://example.com/cover.jpg')
->description('This Database has been created by Laravel')
->createInPage('0adbc2eb47e84569a700a60d537615be');createInDatabase method. Pages created in databases can have custom properties, provided they match the database structure. Properties not explicitly set will default to the database's default value (usually empty).use FiveamCode\LaravelNotionApi\Entities\Properties\Title;
use FiveamCode\LaravelNotionApi\Entities\Page;
use FiveamCode\LaravelNotionApi\Facades\Notion;
// The UUID of the parent Notion Database
$parentDatabaseId = 'f7a7c7f7-7f7f-7f7f-7f7f-7f7f7f7f7f7f';
$page = new Page();
$page->set('title', Title::value('I was created from Laravel'));
Notion::pages()->createInDatabase($parentDatabaseId, $page);A FilterBag allows you to combine multiple filters using AND or OR logic.
FilterBag::and() or FilterBag::or() for quick instantiation.addFilter() for individual filters, addFilterBag() for nested bags, or addFilters() for a collection of filters.FilterBag can contain another FilterBag, but that child bag cannot contain further bags. Exceeding this limit throws a HandlingException.use FiveamCode\LaravelNotionApi\Query\Filters\Filter;
use FiveamCode\LaravelNotionApi\Query\Filters\FilterBag;
use FiveamCode\LaravelNotionApi\Query\Filters\Operators;
// Condition: ('Known for' CONTAINS 'Univac' AND ('Name' EQUALS 'Grace' OR 'Name' EQUALS 'Jean'))
$filterBag = new FilterBag(Operators::AND);
$filterBag->addFilter(
Filter::rawFilter("Known for", ["multi_select" => [Operators::CONTAINS => "UNIVAC']])
);
$nameFilterBag = new FilterBag(Operators::OR);
$nameFilterBag
->addFilter(Filter::textFilter("Name", Operators::EQUALS, "Grace Hopper"))
->addFilter(Filter::textFilter("Name", Operators::EQUALS, "Jean Bartik"));
$filterBag->addFilterBag($nameFilterBag);
Notion::database("DATABASE_ID")
->filterBy($filterBag)
->query()
->asCollection();Page object, you can use it directly; otherwise, instantiate a new Page object and set the ID manually before calling the update method.use FiveamCode\LaravelNotionApi\Entities\Properties\Title;
use FiveamCode\LaravelNotionApi\Entities\Page;
use FiveamCode\LaravelNotionApi\Facades\Notion;
$page = new Page();
$page->setId($pageId); // Set the UUID of the page to update
// Set the properties to be updated
$page->set('title', Title::value('Updated Title'));
Notion::pages()->update($page);