darvis / laravel-ai-generator
AI content generation service for Laravel applications with OpenAI support
Requires
- php: ^8.2
- illuminate/http: ^11.0|^12.0|^13.0
- illuminate/support: ^11.0|^12.0|^13.0
Requires (Dev)
- larastan/larastan: ^3.0
- laravel/pint: ^1.0
- mockery/mockery: ^1.6
- orchestra/testbench: ^9.0|^10.0|^11.0
- pestphp/pest: ^3.0|^4.0
- pestphp/pest-plugin-laravel: ^3.0|^4.0
- phpunit/phpunit: ^11.0|^12.0|^13.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-09-21 11:26:09 UTC
README
darvis/laravel-ai-generator writes structured content for a Laravel application with OpenAI. You pass a ContentRequest with a topic and get a ContentResult with a title, an intro, the main text as HTML, an SEO title, a meta description and optionally an image.
Features
- One call returns
title,intro,text(HTML withh2,p,ulandli),seoTitleandseoDescription. - Asks the OpenAI Responses API for strict JSON, so you get separate fields instead of one text to parse.
- Optional image through the OpenAI image API, and
generateImage()for an image without text. - Language, tone, reading level, audience, keywords, brand, call to action and length per request, with defaults in the config.
- A failing image does not lose the text: the result comes back with
hasError()true. - Another AI provider for the text through your own
AiContentDriver. - No routes, views or migrations: you call it from your own code and store the result yourself.
- Ships a Laravel Boost guideline and skill, so an AI assistant in your application knows the API.
Requirements
- PHP 8.2 or higher (Laravel 13 itself needs PHP 8.3)
- Laravel 11, 12 or 13
- An OpenAI API key; OpenAI bills every call to your OpenAI account
Installation
composer require darvis/laravel-ai-generator
Add your OpenAI API key to .env:
OPENAI_API_KEY=your-api-key-here
Publishing the config file is optional:
php artisan vendor:publish --tag=ai-generator-config
Quick start
use Darvis\LaravelAiGenerator\ContentRequest; use Darvis\LaravelAiGenerator\Facades\AiGenerator; $result = AiGenerator::generate(new ContentRequest( topic: 'The benefits of Laravel for web development', language: 'en', includeImage: false, )); $result->title; // the headline $result->intro; // two to four sentences, plain text $result->text; // the article as HTML $result->seoTitle; // the model is asked for at most 60 characters $result->seoDescription; // the model is asked for at most 155 characters
includeImage is true by default. Leave out includeImage: false and the package also generates an image, which is a second, billed call to OpenAI. The text field is HTML written by a model: sanitise it before you render it unescaped.
Documentation
The full documentation lives on the documentation site:
- Installation: step by step, with a check that costs nothing
- Usage: a complete example, every request option, images, errors and queued jobs
- Configuration: every option and environment variable
- Custom drivers: let another AI provider write the text
- Testing: test your code without calling OpenAI
- Troubleshooting: every error message with cause and fix
- API reference: every public class and method
- FAQ: the short answers
Laravel Boost
The package ships a Laravel Boost guideline and skill. Run php artisan boost:install, or php artisan boost:update --discover in a project that already uses Boost.
Testing
composer test # Pest composer lint # Pint, check only; composer format fixes composer analyse # Larastan
Changelog
See CHANGELOG.
Contributing
See CONTRIBUTING.
Security
Please report a vulnerability privately, as described in SECURITY, not in the issue tracker.
License
The MIT License (MIT). See LICENSE.