Picture of the author

Notion Pages

Handle Properties

There are several Page Properties available within Notion. They control the format and behaviour within Databases.

This package provides a straightforward structure for handling page properties, making them easy to access. More property types will be added in the future. You can already access all properties, but unsupported ones only have the raw Notion API structure.

Supported Property Types

  • Checkbox
  • CreatedBy
  • CreatedTime
  • Date (with and without time)
  • Email
  • Files
  • Formula
  • LastEditedBy
  • LastEditedTime
  • MultiSelect
  • Number
  • People
  • PhoneNumber
  • Relation
  • Rollup
  • Select
  • Text
  • Title
  • Url

Handle Properties

Every property has a parent Notion Page.
Please refer to Fetch Pages and Create and Modify Pages for page specific handling.

Retrieve Properties

$propertyName = 'Your Property Title';

# Get the desired property
# If unsupported:   `*\Entities\Properties\Property`
# If supported:     `*\Entities\Properties\{PropertyType}`
$property = $page->getProperty($propertyName);

# Retrieve all properties as `Illuminate\Support\Collection`
$collectionOfProperties = $page->getProperties();

In order to access general and raw content of all properties you can use the methods of Property::class.

# Get Property Title
$property->getTitle();

# Get Property Type
$property->getType();

# Get the base content of the property 
# raw content, if unsupported
$property->getContent();

# Get the raw content of the property
$property->getRawContent();

# Get string formatted content of the property (will be a JSON string, if unsupported)
$property->asText();

In order to easily access the content of each supported property you can use several helper methods.

Checkbox

$checkboxProp->isChecked(); // returns `bool`

CreatedBy

$createdByProp->getUser(); // returns `*\Entities\User`

CreatedTime

$createdTimeProp->getContent(); // returns `DateTime`

Date (with and without time)

$dateProp->getStart(); // returns `DateTime` (single or start-date)
$dateProp->getEnd(); // returns `DateTime` (end-date)
$dateProp->hasTime(); // returns `bool`

Email

$emailProp->getEmail(); // returns `string`

Files

$filesProp->getFiles(); // returns a `Illuminate\Support\Collection` of strings

Formula

$formulaProp->getContent(); // returns `mixed`
$formulaProp->getFormulaType(); // returns `string`

LastEditedBy

$lastEditedByProp->getUser(); // returns `*\Entities\User`

LastEditedTime

$lastEditedTimeProp->getContent(); // returns `DateTime`

MultiSelect

$multiSelectProp->getItems(); // returns `Illuminate\Support\Collection` of `*\Entities\SelectItem`
$multiSelectProp->getOptions(); // returns `Illuminate\Support\Collection` of `*\Entities\SelectItem`
$multiSelectProp->getNames(); // returns `Illuminate\Support\Collection` of `string`
$multiSelectProp->getColors(); // returns `Illuminate\Support\Collection` of `string`

Number

$numberProp->getNumber(); // returns `float`

People

$peopleProp->getPeople(); // returns `Illuminate\Support\Collection` of `*/Entities/User`

PhoneNumber

$phoneNumberProp->getPhoneNumber(); // returns `string`

Relation

$relationProp->getRelation(); // returns `Illuminate\Support\Collection` of page IDs

Rollup

$rollupProp->getContent(); // returns `mixed`
$rollupProp->getRollupType(); // returns `string`
$rollupProp->getRollupContentType(); // returns `string`

Select

$selectProp->getItem(); // returns `*\Entities\SelectItem`
$selectProp->getOptions(); // returns `Illuminate\Support\Collection` of `*\Entities\SelectItem`
$selectProp->getName(); // returns `string`
$selectProp->getColor(); // returns `string`

Text

$textProp->getRichText(); // returns `*\Entities\PropertyItems\RichText`
$textProp->getPlainText(); // returns `string`

Title

$titleProp->getRichText(); // returns `*\Entities\PropertyItems\RichText`
$titleProp->getPlainText(); // returns `string`

Url

$urlProp->getUrl(); // returns `string`

Create and Set Properties

Each property in Notion has a specific structure. To avoid using the wrong type or structure, each property has a dedicated class and value-methods for easy creation.

use FiveamCode\LaravelNotionApi\Entities\Properties\Text;

# Creating a new Property
$textProperty = Text::value('This is a Text Property');

# Setting the property of a Notion Page
$notionPage->setProperty('Text Property', $textProperty);

All supported properties can be created this way. Below you can find a list of all supported properties and their dedicated classes.

Please be aware, that use has been deliberately omitted for better readability. You can find all Properties within this namespace: FiveamCode\LaravelNotionApi\Entities\Properties.

CreatedBy / CreatedTime / LastEditedBy / LastEditedTime

These properties are readonly.

Files / Formula / Rollup

Currently not supported (by this package).

Checkbox

$checkboxProperty = Checkbox::value($boolean);

Date (with and without time)

# Both $startDate and $endDate are `DateTime`
# Any time information will be ignored
$dateProperty = Date::value($startDate, $endDate /* optional */);

# Both $startDate and $endDate are `DateTime`
# Your time information will be set within the Property in Notion
$dateProperty = Date::valueWithTime($startDate, $endDate /* optional */);

Email

$emailProperty = Email::value($email);

MultiSelect

The given items can be any string. If the item is not available in the Notion select, it will be created.

$items = ['Item 1', 'Item 2', 'Item 3'];
$multiSelectProperty = MultiSelect::value($items);

Number

$numberProperty = Number::value($number); // $number is a `float`

People

Values have to be valid UUIDs of users within the Notion Workspace.

$people = ['user-id-1', 'user-id-2', 'user-id-3'];
$peopleProperty = People::value($people);

PhoneNumber

$phoneNumberProperty = PhoneNumber::value($phoneNumber); // $phoneNumber is a `string`

Relation

Values have to be valid UUIDs of pages within a related database of the Notion Workspace.

$relations = ['page-id-1', 'page-id-2', 'page-id-3'];
$relationProperty = Relation::value($relations);

Select

The given item can be any string. If the item is not available in Notion, it will be created.

$item = 'Item 1';
$selectProperty = Select::value($item);

Text

$textProperty = Text::value($text); // $text is a `string` or `*\Entities\PropertyItems\RichText`

Title

$titleProperty = Title::value($title); // $title is a `string` or `*\Entities\PropertyItems\RichText`

Url

$urlProperty = Url::value($url); // $url is a `string`
Previous
Fetch Pages