litstack / wikipedia
v0.6
2022-10-28 07:42 UTC
Requires
- php: ^8.0
- guzzlehttp/guzzle: ^7.3
- litstack/litstack: ^3.0
README
使用维基百科作为内容来源。
配置
您可以通过向您的config/lit.php
中的fields
键添加wikipedia
设置来配置缓存时间
'fields' => [ // ... 'wikipedia' => [ 'cache_ttl' => 60 * 60 * 24, ], ],
用法
维基百科表单字段的使用方法如下
$form->wikipedia('wiki');
在您的模型中,您需要提供一个json列,并且需要正确地进行转换
// in your model protected $casts = [ 'wiki' => 'json', ];
如果您想禁用section
或chars
输入,可以按照以下方式操作
$form->wikipedia('wiki')->section(false)->chars(false);
显示内容
为了加载维基百科文章的内容,您可以使用Wikipedia
外观。
// will output the first 'intro' section of the article Wikipedia::load('https://en.wikipedia.org/wiki/PHP');
您还可以选择特定的部分
// will output the 'Mascot' section. Wikipedia::load('https://en.wikipedia.org/wiki/PHP', 'Mascot');
您也可以设置字符的最大数量
// will output the first 100 chars of the 'Mascot' section. Wikipedia::load('https://en.wikipedia.org/wiki/PHP', 'Mascot', 100);