This package offer a wrapper around the Apple News API and Apple News Format in PHP. It includes support for Laravel, Wordpress and an HTML parser.
composer require urbania/apple-news
- Add the Service Provider in the config file
config/app.php
:
'providers' => [
// ...
\Urbania\AppleNews\Laravel\AppleNewsServiceProvider::class,
// ...
]
- Add the Facade in the config file
config/app.php
:
'facades' => [
// ...
'AppleNews' => \Urbania\AppleNews\Laravel\AppleNewsFacade::class,
// ...
]
Publish the config file to config/apple-news.php
:
php artisan vendor:publish
Create a test article:
require __DIR__ . '/vendor/autoload.php';
use Urbania\AppleNews\Article;
$article = new Article([
'identifier' => 'test-article',
'language' => 'en-US',
'version' => '1.7',
'layout' => [
'columns' => 12,
'width' => 1024
],
'title' => 'An article',
'components' => [
[
'role' => 'title',
'text' => 'This is a title'
],
[
'role' => 'body',
'text' => 'This is a body'
]
]
]);
echo $article->toJson();
Create a test article: (when creating an article with the facade or the helper, it takes into account the default article
values found in config/apple-news.php
)
// Using the facade
use AppleNews;
$article = AppleNews::article([
'identifier' => 'test-article',
'title' => 'An article',
'components' => [
[
'role' => 'title',
'text' => 'This is a title'
],
[
'role' => 'body',
'text' => 'This is a body'
]
]
]);
// Using the helper
$article = article([
// ... same as above
]);
echo $article->toJson();