https://github.com/litstack/wikipedia-field
https://github.com/litstack/wikipedia-field
Last synced: about 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/litstack/wikipedia-field
- Owner: litstack
- Created: 2021-06-23T10:06:27.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2022-10-28T07:52:31.000Z (about 3 years ago)
- Last Synced: 2025-02-16T14:51:33.853Z (11 months ago)
- Language: PHP
- Size: 182 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Wikipedia-Field
Use Wikipedia as the source for your content.
## Config
You can configure the cache time by adding the `wikipedia` settings to the `fields` key in your `config/lit.php`
```php
'fields' => [
// ...
'wikipedia' => [
'cache_ttl' => 60 * 60 * 24,
],
],
```
## Usage
The wikipedia formfield is used as follows:
```php
$form->wikipedia('wiki');
```
In your Model you need to provide a json column wich is cast properly:
```php
// in your model
protected $casts = [
'wiki' => 'json',
];
```
If you want to disable the `section` or `chars` inputs you can do it as follows:
```php
$form->wikipedia('wiki')->section(false)->chars(false);
```
### Displaying Content
In order to load the content of a wikipedia article you can use the `Wikipedia` facade.
```php
// will output the first 'intro' section of the article
Wikipedia::load('https://en.wikipedia.org/wiki/PHP');
```
You can also select a specific section:
```php
// will output the 'Mascot' section.
Wikipedia::load('https://en.wikipedia.org/wiki/PHP', 'Mascot');
```
You might as well set a maximum amout of characters:
```php
// will output the first 100 chars of the 'Mascot' section.
Wikipedia::load('https://en.wikipedia.org/wiki/PHP', 'Mascot', 100);
```