# Getting started with Laravel AI Blog

**Install it, and your blog thinks.** Laravel AI Blog is a free, open-source blog package for Laravel 10 to 13. It
plans topics, drafts *with* you, scores every post for on-page SEO, links itself, keeps itself fresh — and lets
Claude, ChatGPT, Claude Code or any MCP agent write to it.

- **Headless by default.** Models, migrations, a trait for your *existing* Post model. No admin panel forced on you. Flip one flag for `/blog` routes, Blade components, RSS and JSON-LD.
- **SEO that nobody else ships.** An on-page score with plain-English fixes, internal-link suggestions with anchor text, stale-post detection, BlogPosting + FAQPage schema.
- **AI as your editor, not your ghostwriter.** Built on the official [laravel/ai](https://github.com/laravel/ai) SDK — any provider. Brief → draft, meta descriptions, rewrites, refresh suggestions, translations. Everything lands as a **draft**. Nothing auto-publishes unless you say so.
- **Agent-ready.** A built-in [laravel/mcp](https://github.com/laravel/mcp) server: *"write a post on X, score it, link it to related posts, schedule for Monday."*
- **Free. MIT.** No Nova license, no Filament lock-in, no SaaS tether.

## Requirements

- PHP 8.2 to 8.5 with the `curl`, `dom`, `libxml` and `mbstring` extensions
- Laravel 10, 11, 12 or 13

Both ends of those ranges run in CI on every push: the newest dependencies and the oldest ones the constraints
allow. Laravel 10 and 11 are end of life; they are supported for apps that have not upgraded, not recommended
for new ones. On PHP 8.4 and later the text extractor uses PHP's spec-compliant HTML5 parser; on older PHP it
falls back to libxml2's HTML parser, which gives the same results on the pages the tests cover but stops at
about 256 levels of nesting (it returns no text for a page nested deeper, never partial text).

## Install

```bash
composer require byteminus/laravel-ai-blog
php artisan vendor:publish --tag=ai-blog-migrations
php artisan migrate
```

Optional, for AI and agents:

```bash
composer require laravel/ai laravel/mcp
```

## 60-second tour

```php
use ByteMinus\AiBlog\Facades\AiBlog;
use ByteMinus\AiBlog\Models\Post;

// Score any post. Deterministic, no API key needed.
$report = $post->seoReport();
$report->score;    // 72
$report->grade();  // "B"
$report->fixes();  // ["Include \"laravel queues\" in the title.", "Add at least two links — ..."]

// Internal links, with anchor text, from your own published posts.
$post->suggestedLinks();   // [['post' => Post, 'anchor' => 'queue workers', 'score' => 0.41], ...]

// AI: keyword → brief → full draft. Saved as a DRAFT for a human to review.
$draft = AiBlog::draftFromKeyword('laravel queues');

// AI: fill in a missing keyword + meta description on an existing post.
AiBlog::enrichSeo($post);

// Publishing is explicit.
$post->schedule(now()->addDays(2));   // then: php artisan ai-blog:publish-scheduled
$post->publish();
```

```bash
php artisan ai-blog:audit            # score every post, list fixes and links
php artisan ai-blog:audit --fix      # let the AI fill missing SEO fields first
php artisan ai-blog:audit --stale    # posts due for a refresh
```
