Back to Blog
AI Content Generation in Laravel: Automating Marketing Copy
Content at Scale
E-commerce sites with thousands of products, marketing teams producing daily content, technical documentation that needs updating—AI can help generate and maintain content at scale while maintaining quality and consistency.
Product Description Generator
class ProductDescriptionGenerator
{
private string $brandVoice = <<brandVoice}
Generate a product description for:
Name: {$product->name}
Category: {$product->category}
Features: {$product->features}
Price: \${$product->price}
Target Customer: {$product->target_customer}
Requirements:
- 150-200 words
- Include a hook in the first sentence
- Highlight 3 key benefits
- End with a subtle call to action
- SEO-friendly with natural keyword integration
PROMPT;
return $this->ai->generate($prompt, [
'temperature' => 0.7,
'max_tokens' => 500,
]);
}
}
Batch Processing
class GenerateProductDescriptions implements ShouldQueue
{
public function handle(): void
{
Product::whereNull('ai_description')
->chunk(100, function ($products) {
foreach ($products as $product) {
GenerateSingleDescription::dispatch($product);
}
});
}
}
A/B Testing Generated Content
class ContentVariantGenerator
{
public function generateVariants(Product $product, int $count = 3): array
{
$variants = [];
$styles = [
'emotional' => 'Focus on how the product makes the customer feel',
'technical' => 'Emphasize specifications and performance metrics',
'social' => 'Highlight popularity and social proof',
];
foreach (array_slice($styles, 0, $count) as $style => $instruction) {
$variants[$style] = $this->generate($product, $instruction);
}
return $variants;
}
}
Quality Control
class ContentQualityChecker
{
public function check(string $content): array
{
return [
'word_count' => str_word_count($content),
'readability' => $this->calculateReadability($content),
'sentiment' => $this->analyzeSentiment($content),
'issues' => $this->detectIssues($content),
];
}
private function detectIssues(string $content): array
{
$issues = [];
if (preg_match('/\b(best|greatest|amazing)\b/i', $content)) {
$issues[] = 'Contains superlatives that may seem exaggerated';
}
if (strlen($content) < 100) {
$issues[] = 'Content may be too short';
}
return $issues;
}
}
Human Review Workflow
class ContentReviewWorkflow
{
public function submit(Product $product, string $content): void
{
ContentReview::create([
'product_id' => $product->id,
'content' => $content,
'status' => 'pending',
'quality_score' => $this->checker->check($content),
]);
}
public function approve(ContentReview $review): void
{
$review->product->update(['description' => $review->content]);
$review->update(['status' => 'approved']);
}
}
Conclusion
AI content generation works best with clear guidelines, quality checks, and human oversight. Use it to scale your content production while maintaining the standards your brand requires.
Related Articles
Need Help With Your Project?
I respond to all inquiries within 24 hours. Let's discuss how I can help build your production-ready system.
Get In Touch