saas-estate/laravel-notion-api

Laravel 对 Notion API 的包装器

资助包维护!
Patreon

dev-main 2023-03-22 22:15 UTC

This package is not auto-updated.

Last update: 2024-10-03 05:47:17 UTC


README

轻松实现 Laravel 与 Notion 的集成

Latest Version on Packagist Total Downloads

本包提供了一种简单明了的方式来访问 Notion API 端点,查询数据以及更新现有条目。

安装

您可以通过 composer 安装此包

composer require fiveam-code/laravel-notion-api

授权

Notion API 需要访问令牌和 Notion 集成,有关如何操作的说明,请参阅 Notion 文档。在 Notion 账户中授予集成访问权限对于启用 API 访问非常重要。

将您的 Notion API 令牌添加到您的 .env 文件中

NOTION_API_TOKEN="$YOUR_ACCESS_TOKEN"

用法

请访问此包的 文档

🔥 快速启动您的 Notion API 项目代码示例

基本设置 (+ 示例)

use FiveamCode\LaravelNotionApi\Notion; 

# Access through Facade (token has to be set in .env)
\Notion::databases()->find($databaseId);

# Custom instantiation (necessary if you want to access more than one NotionApi integration)
$notion = new Notion($apiToken, $apiVersion); // version-default is 'v1'
$notion->databases()->find($databaseId);

获取页面信息

// Returns a specific page
\Notion::pages()->find($yourPageId);

搜索

// Returns a collection pages and databases of your workspace (included in your integration-token)
\Notion::search($searchText)
        ->query()
        ->asCollection();

查询数据库

// 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()
      ->asCollection();

测试

vendor/bin/phpunit tests

支持

如果您在使用此包的某个项目中,或者只是想支持我们的开发,请考虑成为 Patreon 的赞助者!

贡献

有关详细信息,请参阅 CONTRIBUTING

安全

如果您发现任何与安全相关的问题,请通过电子邮件 hello@dianaweb.dev 联系我们,而不是使用问题跟踪器。

使用情况

  • Julien Nahum 使用 notionforms.iolaravel-notion-api 创建了 notionforms.io,它允许您轻松创建基于在 Notion 中选择的数据库的定制表单。
  • GitHub Notion Sync 是由 Beyond Code 提供的一项服务,可以将多个 GitHub 仓库的问题同步到 Notion 数据库中
  • Notion Invoice 是为使用 Notion 的自由职业者和企业提供的首个高级发票解决方案。从您的 Notion 数据创建美观的 PDF 发票。

如果您在项目中使用此包,请打开 PR 以将其添加到此部分!

鸣谢

许可证

MIT 许可证 (MIT)。有关更多信息,请参阅 许可证文件