|
1 | 1 | <h1 align="center"> Notion for Laravel</h1>
|
2 | 2 |
|
3 |
| -<img src="https://banners.beyondco.de/Notion%20for%20Laravel.png?theme=light&packageManager=composer+require&packageName=fiveam-code%2Flaravel-notion-api&pattern=architect&style=style_1&description=Effortless+Notion+integrations+with+Laravel&md=1&showWatermark=1&fontSize=100px&images=https%3A%2F%2Flaravel.com%2Fimg%2Flogomark.min.svg"> |
| 3 | +<div align="center"> |
| 4 | +<img src="https://notionforlaravel.com/images/open-graph.png" alt="Notion For Laravel" width="500"> |
4 | 5 |
|
| 6 | +[](https://github.com/5am-code/laravel-notion-api/actions/workflows/main.yml) |
5 | 7 | [](https://packagist.org/packages/fiveam-code/laravel-notion-api)
|
6 | 8 | [](https://packagist.org/packages/fiveam-code/laravel-notion-api)
|
7 | 9 |
|
8 | 10 | [comment]: <> ()
|
9 |
| - |
| 11 | +</div> |
10 | 12 | This package provides a simple and crisp way to access the Notion API endpoints, query data and update existing entries.
|
11 | 13 |
|
| 14 | +# Documentation |
| 15 | + |
| 16 | +For a extensive documentation, more context and usage examples, head over to the official documentation at [notionforlaravel.com](https://notionforlaravel.com). |
| 17 | + |
| 18 | + |
| 19 | +# Quick Start Guide |
| 20 | + |
| 21 | +All examples refer to our test database, which you can |
| 22 | +find [here](https://dianawebdev.notion.site/8284f3ff77e24d4a939d19459e4d6bdc?v=bc3a9ce8cdb84d3faefc9ae490136ac2). |
12 | 23 |
|
13 | 24 | ## Installation
|
14 | 25 |
|
15 |
| -1. You can install the package via composer: |
| 26 | +The package is compatible with Laravel 8, 9 and 10. The minimum PHP requirement is 8.0. |
16 | 27 |
|
17 |
| - ```bash |
18 |
| - composer require fiveam-code/laravel-notion-api |
19 |
| - ``` |
| 28 | +1. Install the package via composer: |
20 | 29 |
|
| 30 | + ```bash |
| 31 | + composer require fiveam-code/laravel-notion-api |
| 32 | + ``` |
21 | 33 |
|
22 | 34 | 2. Get your Notion API access token like explained in [their documentation](https://developers.notion.com/). It's also
|
23 |
| -important to grant access to the integration within your Notion pages, which is described in the developer documentation at Notion as well. |
| 35 | + important to grant access to the integration within your Notion pages, which is described in the developer |
| 36 | + documentation at Notion as well. |
| 37 | + |
| 38 | +3. Add a new line to your applications `.env` file: |
| 39 | + |
| 40 | + ```bash |
| 41 | + NOTION_API_TOKEN="$YOUR_ACCESS_TOKEN" |
| 42 | + ``` |
24 | 43 |
|
25 |
| -3. For internal Integrations, please add a new entry to your `.env` like the following: |
| 44 | +4. You're ready to go! You can now access Notion endpoints through the `Notion` facade: |
26 | 45 |
|
27 |
| - ```bash |
28 |
| - NOTION_API_TOKEN="$YOUR_ACCESS_TOKEN" |
29 |
| - ``` |
30 |
| -4. Now you can easily access Notion: |
31 |
| - ```php |
32 |
| - use \Notion; |
33 |
| - |
34 |
| - Notion::databases()->find($databaseId); |
35 |
| - ``` |
| 46 | + ```php |
| 47 | + use \Notion; |
36 | 48 |
|
37 |
| - That's it. |
| 49 | + Notion::databases()->find("8284f3ff77e24d4a939d19459e4d6bdc"); |
| 50 | + ``` |
38 | 51 |
|
| 52 | + That's it. |
39 | 53 |
|
40 |
| -## Usage |
| 54 | +For detailed usage information and a list of available endpoints see (the docs). |
41 | 55 |
|
42 |
| -Head over to the [Documentation](https://notionforlaravel.com) of this package. |
| 56 | +## Examples |
43 | 57 |
|
44 |
| -### 🔥 Code Examples to jumpstart your next Notion API Project |
45 | 58 |
|
46 |
| -#### Fetch a Notion Database (through a Facade) |
| 59 | +### Fetch a Notion Database |
| 60 | + |
| 61 | +The `databases()->find()` method returns a `FiveamCode\LaravelNotionApi\Entities\Database` object, |
| 62 | +which contains all the information about the database, including its properties and the possible values for each |
| 63 | +property. |
| 64 | + |
47 | 65 | ```php
|
48 |
| -use \Notion; |
| 66 | +use \Notion; |
49 | 67 |
|
50 | 68 | Notion::databases()
|
51 |
| - ->find("a7e5e47d-23ca-463b-9750-eb07ca7115e4"); |
| 69 | + ->find("8284f3ff77e24d4a939d19459e4d6bdc"); |
52 | 70 | ```
|
53 | 71 |
|
54 |
| -#### Fetch a Notion Page |
| 72 | +### Fetch a Notion Page |
| 73 | + |
| 74 | +The `pages()->find()` method returns a `FiveamCode\LaravelNotionApi\Entities\Page` object, |
| 75 | +which contains all the information about the page, including its properties and the possible values for each property. |
| 76 | + |
55 | 77 | ```php
|
56 | 78 | Notion::pages()
|
57 | 79 | ->find("e7e5e47d-23ca-463b-9750-eb07ca7115e4");
|
58 | 80 | ```
|
59 | 81 |
|
60 |
| -#### Search |
| 82 | +### Search |
| 83 | + |
| 84 | +The `search()` endpoint returns a collection of pages that match the search query. The scope of the search is limited to |
| 85 | +the workspace that the integration is installed in |
| 86 | +and the pages that are shared with the integration. |
| 87 | + |
61 | 88 | ```php
|
62 |
| -// Returns a collection pages and databases of your workspace (included in your integration-token) |
63 |
| -Notion::search("My Notion Search") |
| 89 | +Notion::search("Search term") |
64 | 90 | ->query()
|
65 | 91 | ->asCollection();
|
66 | 92 | ```
|
67 | 93 |
|
68 |
| -#### Query Database |
| 94 | +### Query Database |
| 95 | + |
| 96 | +The `database()` endpoint allows you to query a specific database and returns a collection of pages (= database |
| 97 | +entries). |
| 98 | +You can filter and sort the results and limit the number of returned entries. For detailed information about the |
| 99 | +available |
| 100 | +filters and sorts, please refer to the [documentation](https://developers.notion.com/reference/post-database-query). |
| 101 | + |
| 102 | +```php |
| 103 | +use FiveamCode\LaravelNotionApi\Query\Filters\Filter; |
| 104 | +use FiveamCode\LaravelNotionApi\Query\Filters\Operators; |
| 105 | + |
| 106 | +$nameFilter = Filter::textFilter('Name', Operators::EQUALS, 'Ada Lovelace'); |
| 107 | + |
| 108 | +\Notion::database("8284f3ff77e24d4a939d19459e4d6bdc") |
| 109 | + ->filterBy($nameFilter) |
| 110 | + ->limit(5) |
| 111 | + ->query() |
| 112 | + ->asCollection(); |
| 113 | +``` |
| 114 | + |
| 115 | +Compound filters for AND or OR queries are also available: |
69 | 116 |
|
70 | 117 | ```php
|
71 |
| -// Queries a specific database and returns a collection of pages (= database entries) |
72 |
| -$sortings = new Collection(); |
73 |
| -$filters = new Collection(); |
74 |
| -
|
75 |
| -$sortings->add(Sorting::propertySort('Ordered', 'ascending')); |
76 |
| -$sortings->add(Sorting::timestampSort('created_time', 'ascending')); |
77 |
| -
|
78 |
| -$filters->add(Filter::textFilter('title', ['contains' => 'new'])); |
79 |
| -// or |
80 |
| -$filters->add(Filter::rawFilter('Tags', ['multi_select' => ['contains' => 'great']])); |
81 |
| - |
82 |
| -Notion::database("a7e5e47d-23ca-463b-9750-eb07ca7115e4") |
83 |
| - ->filterBy($filters) // filters are optional |
84 |
| - ->sortBy($sortings) // sorts are optional |
85 |
| - ->limit(5) // limit is optional |
86 |
| - ->query() |
87 |
| - ->asCollection(); |
| 118 | +use Illuminate\Support\Collection; |
| 119 | +use FiveamCode\LaravelNotionApi\Query\Filters\Filter; |
| 120 | +use FiveamCode\LaravelNotionApi\Query\Filters\FilterBag; |
| 121 | +use FiveamCode\LaravelNotionApi\Query\Filters\Operators; |
| 122 | +use FiveamCode\LaravelNotionApi\Query\Sorting; |
| 123 | + |
| 124 | +# Give me all entries that are |
| 125 | +# (KnownFor == UNIVAC || KnownFor == ENIAC) |
| 126 | +# and sort them by name ascending |
| 127 | + |
| 128 | +$filterBag = new FilterBag(Operators::AND); |
| 129 | + |
| 130 | +$filterBag->addFilter( |
| 131 | + Filter::rawFilter("Known for", [ |
| 132 | + "multi_select" => [Operators::CONTAINS => "UNIVAC"], |
| 133 | + ]) |
| 134 | +); |
| 135 | + |
| 136 | +$filterBag->addFilter( |
| 137 | + Filter::rawFilter("Known for", [ |
| 138 | + "multi_select" => [Operators::CONTAINS => "ENIAC"], |
| 139 | + ]) |
| 140 | +); |
| 141 | + |
| 142 | +\Notion::database("8284f3ff77e24d4a939d19459e4d6bdc") |
| 143 | + ->filterBy($filterBag) |
| 144 | + ->sortBy(Sorting::propertySort('Name', 'ascending')) |
| 145 | + ->limit(5) |
| 146 | + ->query() |
| 147 | + ->asCollection(); |
88 | 148 | ```
|
89 | 149 |
|
| 150 | +### Tests |
| 151 | + |
| 152 | +You can find even more usage examples by checking out the package tests in the `/tests` directory. |
| 153 | +We are using [Pest](https://pestphp.com/) for out tests and are currently in the process of switching all existing PHPUnit tests to Pest. |
90 | 154 |
|
91 |
| -### Testing (pestphp) |
| 155 | +If you want to run the tests in your CLI: |
92 | 156 |
|
93 | 157 | ```bash
|
94 | 158 | vendor/bin/pest tests
|
95 | 159 | ```
|
96 | 160 |
|
97 |
| -## Support |
| 161 | +# Support |
| 162 | + |
| 163 | +## Supported by Tinkerwell |
98 | 164 |
|
99 |
| -If you use this package in one of your projects or just want to support our development, consider becoming a [Patreon](https://www.patreon.com/bePatron?u=56662485)! |
| 165 | +<a href="https://tinkerwell.app/"> |
| 166 | +<img src="https://tinkerwell.app/images/tinkerwell_logo.png" width="64" height="64" alt="Tinkerwell"> <br/> |
| 167 | +</a> |
100 | 168 |
|
101 |
| -## Contributing |
| 169 | +The development of this package is supported by [Tinkerwell](https://tinkerwell.app/). |
| 170 | + |
| 171 | + |
| 172 | +# Contributing |
102 | 173 |
|
103 | 174 | Please see [CONTRIBUTING](CONTRIBUTING.md) for details.
|
104 | 175 |
|
105 |
| -## Security |
| 176 | +# Security |
106 | 177 |
|
107 | 178 | If you discover any security related issues, please email hello@dianaweb.dev instead of using the issue tracker.
|
108 | 179 |
|
109 |
| -## Credits |
| 180 | +# Credits |
110 | 181 |
|
111 | 182 | - [Diana Scharf](https://github.com/mechelon)
|
112 | 183 | - [Johannes Güntner](https://github.com/johguentner)
|
113 | 184 |
|
114 |
| -
|
115 | 185 | <p align="center">
|
116 | 186 | <img src="https://5amco.de/images/5am.png" width="200" height="200">
|
117 | 187 | </p>
|
118 | 188 |
|
119 |
| -## License |
| 189 | +# License |
120 | 190 |
|
121 | 191 | The MIT License (MIT). Please see [License File](LICENSE.md) for more information.
|
0 commit comments