Laravel AI Generator
darvis/laravel-ai-generator turns a topic into the fields a web page needs, with one call to OpenAI. You pass a ContentRequest, you get a ContentResult with a title, an intro, the main text as HTML, an SEO title, a meta description and, if you want one, an image.
It is for Laravel developers who build a CMS, a blog or a web shop and want a first draft of a text without writing prompts and parsing API responses themselves.
What it does not do
- It has no routes, views, migrations or screens. You call it from your own code.
- It does not save anything. You store the result, and the image, yourself.
- It does not sanitise the generated HTML. See Usage.
- It does not queue anything by itself. See Usage.
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; the package is free.
Install
composer require darvis/laravel-ai-generator
OPENAI_API_KEY=your-api-key-here
Then follow Check that it works.
In short
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: h2, p, ul and li
$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.
Pages
- Installation: from
composer requireto a first result, and a check that costs nothing. - Usage: one complete example, every request option, the result, images, errors and queued jobs.
- Configuration: every config key and environment variable with its default.
- Custom drivers: let another AI provider write the text.
- Testing: test your own code without calling OpenAI.
- Troubleshooting: every error message the package produces, with cause and fix.
- API reference: every public class, method and exception message.
- FAQ: the short answers.