articlai / articlai-laravel
Package to allow blog publishing in Laravel using Articlai
Fund package maintenance!
Articlai
Installs: 10
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 1
pkg:composer/articlai/articlai-laravel
Requires
- php: ^8.3
- illuminate/contracts: ^10.0||^11.0||^12.0
- spatie/laravel-medialibrary: ^11.13
- spatie/laravel-package-tools: ^1.16
Requires (Dev)
- laravel/pint: ^1.14
- nunomaduro/collision: ^8.1.1||^7.10.0
- orchestra/testbench: ^10.0.0||^9.0.0||^8.22.0
- pestphp/pest: ^3.0
- pestphp/pest-plugin-arch: ^3.0
- pestphp/pest-plugin-laravel: ^3.0
README
A Laravel package that enables seamless integration with ArticlAI's Custom API connection type. This package provides secure API endpoints that allow ArticlAI to create, update, and delete blog posts in your Laravel application.
Installation
You can install the package via composer:
composer require articlai/articlai-laravel
You can publish and run the migrations with:
php artisan vendor:publish --tag="articlai-laravel-migrations" php artisan vendor:publish --tag="medialibrary-migrations" php artisan migrate
You can publish the config file with:
php artisan vendor:publish --tag="articlai-laravel-config"
Configuration
After publishing the config file, update your .env
file with your ArticlAI settings:
# Authentication Method (api_key, bearer_token, or basic_auth) ARTICLAI_AUTH_METHOD=api_key ARTICLAI_API_KEY=your-secret-api-key
API Endpoints
The package provides the following endpoints for ArticlAI integration:
Validation Endpoint
GET /api/articlai/validate
Returns platform information and validates the connection.
Content Management
POST /api/articlai/posts # Create a new post
GET /api/articlai/posts/{id} # Get a specific post
PUT /api/articlai/posts/{id} # Update a post
DELETE /api/articlai/posts/{id} # Delete a post
Banner Images
The package supports banner images through Spatie Media Library integration. When creating or updating posts, you can include banner image URLs:
{ "title": "Blog Post Title", "content": "<p>Post content</p>", "banner_image": "https://example.com/image.jpg", "banner_original": "https://example.com/original.jpg" }
The package will automatically download and store the images, creating multiple conversions:
- thumbnail: 150x150px (cropped)
- medium: 300x300px (cropped)
- large: 800x600px (cropped)
- original: Original image
Usage
Using the Service Class
use Articlai\Articlai\Articlai; $articlai = app(Articlai::class); // Create a post with banner image $post = $articlai->createPost([ 'title' => 'My Blog Post', 'content' => '<p>This is the content</p>', 'excerpt' => 'Post excerpt', 'status' => 'published', 'banner_image' => 'https://example.com/banner.jpg' ]); // Update a post $updatedPost = $articlai->updatePost($post->id, [ 'title' => 'Updated Title' ]); // Get posts $posts = $articlai->getPosts(['status' => 'published']);
Using the Facade
use Articlai\Articlai\Facades\Articlai; $post = Articlai::createPost([ 'title' => 'My Blog Post', 'content' => '<p>This is the content</p>' ]);
Using the Model Directly
use Articlai\Articlai\Models\ArticlaiPost; $post = ArticlaiPost::create([ 'title' => 'My Blog Post', 'content' => '<p>This is the content</p>', 'status' => 'published' ]); // Get published posts $publishedPosts = ArticlaiPost::published()->get(); // Access banner images $post = ArticlaiPost::find(1); echo $post->banner_image; // Large version URL echo $post->banner_thumbnail; // Thumbnail URL echo $post->banner_medium; // Medium URL echo $post->banner_large; // Large URL echo $post->banner_original; // Original URL
Command Line Interface
Check the package status and view recent posts:
php artisan articlai:status --posts=10
Testing
composer test
Credits
License
The MIT License (MIT). Please see License File for more information.