darvis / laravel-ai-generator
AI content generation for Laravel with Claude, ChatGPT, Gemini and Grok: articles, SEO fields and images, with a setup wizard and an MCP server
Requires
- php: ^8.2
- illuminate/console: ^11.0|^12.0|^13.0
- illuminate/http: ^11.0|^12.0|^13.0
- illuminate/support: ^11.0|^12.0|^13.0
- laravel/prompts: ^0.1.20|^0.2|^0.3
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
- laravel/mcp: Required for the MCP server that lets an assistant generate content through your app (^1.0, Laravel 12.41+).
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-09-25 08:17:10 UTC
README
darvis/laravel-ai-generator writes structured content for a Laravel application with Claude, ChatGPT, Gemini or Grok. 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. - Four providers out of the box: OpenAI (ChatGPT), Anthropic (Claude), Google (Gemini) and xAI (Grok). Every one is asked for strict JSON, so you get separate fields instead of one text to parse.
- Use several at once: one provider writes, another makes the images (Claude has no image model), and others take over when the first one fails. Pick another provider or model per call with
AiGenerator::using('anthropic'). - A setup wizard,
php artisan ai-generator:install, that checks every API key with the provider, lets you pick the models your key may use and writes.envfor you.php artisan ai-generator:statuschecks the keys again at no cost. - An MCP server (with
laravel/mcp), so an assistant such as Claude Code can generate content and images through your application. - 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. - 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 API key of at least one provider. A ChatGPT, Claude or Gemini subscription is not an API key: the API is billed separately, per call. The API keys guide shows step by step where to create one.
- Optional:
laravel/mcp(Laravel 12.41 or newer) for the MCP server
Installation
composer require darvis/laravel-ai-generator php artisan ai-generator:install
The wizard asks which providers you have a key for, checks each key, and writes the settings to .env. You can also set them by hand:
ANTHROPIC_API_KEY=your-claude-key OPENAI_API_KEY=your-openai-key AI_GENERATOR_DRIVER=anthropic # Claude writes the text AI_GENERATOR_IMAGE_DRIVER=openai # OpenAI makes the images AI_GENERATOR_FALLBACKS=openai # OpenAI writes when Claude fails
Never commit .env or put a key in your code. 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
Another provider or model for one call:
$result = AiGenerator::using('claude')->generate($request); $result = AiGenerator::using('openai', 'gpt-4.1-mini')->generate($request);
includeImage is true by default. Leave out includeImage: false and the package also generates an image, which is a second, billed call. 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:
- API keys: where to create a key for each provider, and how to keep it secret
- Installation: the wizard step by step, with a check that costs nothing
- Multiple providers: default, image and fallback drivers, and
using() - MCP server: let an assistant generate content through your app
- 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 a real API
- 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.
Support the package
If darvis/laravel-ai-generator saves you time, a star on GitHub or a favourite on Packagist helps other developers find it.
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.