Add Post Templates feature

- Create templates table with name, body, type, title, target, placeholders
- Add Template model with applyToPost method for placeholder replacement
- Add Livewire Templates/Index component for CRUD operations
- Add templates index view with form and table
- Add /templates route
- Update Posts/Index to support template selection when creating posts
- Templates can be applied to pre-fill post form fields

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
This commit is contained in:
m105
2026-07-27 21:00:41 +03:00
parent b3b250aaca
commit 2a41328130
7 changed files with 342 additions and 0 deletions
+54
View File
@@ -0,0 +1,54 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Template extends Model
{
use HasFactory;
public const TYPES = [
'twitter', 'instagram', 'facebook', 'reddit',
'tiktok', 'linkedin', 'youtube', 'blog', 'other',
];
protected $fillable = [
'name',
'body',
'type',
'title',
'target',
'placeholders',
];
protected $casts = [
'placeholders' => 'array',
];
public function applyToPost(array $data): array
{
$result = [
'title' => $this->title,
'body' => $this->body,
'type' => $this->type,
'target' => $this->target,
];
// Replace placeholders in all text fields
if ($this->placeholders && is_array($data)) {
foreach ($data as $key => $value) {
if (in_array($key, $this->placeholders)) {
foreach (['title', 'body', 'target'] as $field) {
if ($result[$field]) {
$result[$field] = str_replace("{{$key}}", $value, $result[$field]);
}
}
}
}
}
return $result;
}
}