## Getting Started
### Minimal Setup
1. **Installation**:
```bash
composer require promptphp/deck
php artisan vendor:publish --provider="PromptPHP\Deck\Providers\DeckServiceProvider"
php artisan migrate
config/deck.php) and migrations for tracking prompt executions.First Prompt:
php artisan make:prompt order-summary
resources/prompts/order-summary/ with versioned files (v1/system.md, v1/user.md).{{ $variable }} syntax for dynamic values.First Usage:
use PromptPHP\Deck\Facades\Deck;
$prompt = Deck::get('order-summary');
$messages = $prompt->toMessages(['tone' => 'friendly', 'order' => $order]);
make:prompt – Scaffold new prompts.prompt:list – View all prompts and versions.prompt:activate – Switch active versions (e.g., php artisan prompt:activate order-summary v2).config/deck.php – Toggle features like auto-scaffolding for Laravel AI agents.make:prompt to create structured directories (system.md, user.md).# v1/system.md
You are a {{ $role }} assistant. Respond in {{ $tone }}.
$prompt->system(['role' => 'customer support', 'tone' => 'professional']);
config(['deck.activated' => ['order-summary' => 'v2']]);
Deck::get('prompt')->diff('v1') to compare versions.prompt:track or auto-track via middleware:
Deck::track('order-summary', ['user_id' => 123]);
HasPromptTemplate to agents to auto-generate instructions():
class OrderAgent extends Agent {
use HasPromptTemplate;
// No manual instructions() needed.
}
config/deck.php:
'auto_scaffold_agents' => true,
Now make:agent creates matching prompt directories.Deck::track('prompt_name', [
'variables' => ['tone' => 'friendly'],
'metadata' => ['user_id' => 1, 'response_time' => 120],
]);
PromptExecutionMiddleware to auto-track API calls:
protected $middleware = [\PromptPHP\Deck\Http\Middleware\TrackPromptExecutions::class];
php artisan prompt:activate order-summary v1 --env=staging
php artisan prompt:activate order-summary v2 --env=production
prompt_executions table:
$executions = \PromptPHP\Deck\Models\PromptExecution::where('prompt_name', 'order-summary')
->where('version', 'v1')
->get();
Version Confusion:
v1 and 1 are equivalent, but mixing formats (e.g., Deck::get('prompt', 1) vs. Deck::get('prompt', 'v1')) may cause issues.v1 for clarity).Variable Interpolation:
{{ $missing }}) render as literal text.$prompt->system(['tone' => 'friendly', 'order' => $order ?? 'N/A']);
File Permissions:
resources/prompts/. Ensure Laravel’s storage permissions allow writes:
chmod -R 755 resources/prompts/
Laravel AI SDK Quirks:
HasPromptTemplate doesn’t auto-generate instructions(), verify:
resources/prompts/order-agent/).prompt_name matches the directory name (case-sensitive).Tracking Overhead:
Deck::track() inserts a row into prompt_executions. For high-volume apps, batch writes:
\PromptPHP\Deck\Facades\Deck::batchTrack([
['prompt_name' => 'order-summary', 'data' => [...]],
['prompt_name' => 'support-agent', 'data' => [...]],
]);
Prompt Not Found:
config/deck.php for prompt_paths (default: resources/prompts).Deck::get('order-summary') → resources/prompts/order-summary/).Version Activation:
php artisan prompt:list to confirm active versions.$activeVersion = Deck::getActiveVersion('order-summary');
Variable Rendering:
$rendered = Deck::render('order-summary', ['tone' => 'friendly']);
Custom Storage:
PromptManager to use a database or cloud storage:
// app/Providers/DeckServiceProvider.php
$this->app->singleton(\PromptPHP\Deck\Contracts\PromptManager::class, CustomPromptManager::class);
Variable Parsers:
{{{ $json }}} for JSON variables):
// app/Providers/DeckServiceProvider.php
Deck::extend('custom_parser', function ($value) {
return json_decode($value);
});
Usage:
# v1/system.md
Process this JSON: {{{ $data }}}
Tracking Events:
prompt.executed events to add custom logic:
\PromptPHP\Deck\Events\PromptExecuted::dispatch($execution);
CLI Customization:
--diff flag to prompt:list):
// app/Console/Commands/CustomPromptList.php
use PromptPHP\Deck\Console\PromptListCommand;
class CustomPromptList extends PromptListCommand {
protected $signature = 'prompt:list {--diff}';
// ...
}
Caching:
$cached = Cache::remember("prompt_{$promptName}", now()->addHours(1), function () use ($promptName) {
return Deck::get($promptName)->toMessages($variables);
});
Bulk Operations:
Deck::getMultiple(['prompt1', 'prompt2']) to load multiple prompts in one query.Database Indexes:
prompt_executions for high-traffic prompts:
Schema::table('prompt_executions', function (Blueprint $table) {
$table->index(['prompt_name', 'version']);
});
Auto-Scaffolding:
make:agent doesn’t create prompts, ensure:
'auto_scaffold_agents' => true, // config/deck.php
php artisan deck:scaffold-agent OrderAgent
Environment-Specific Versions:
.env to override active versions:
DECK_ACTIVATED_ORDER_SUMMARY=v2
DeckServiceProvider:
$this->app->singleton(PromptManager::class, function () {
$manager = new PromptManager();
$manager->setActivatedVersions(config('deck.activated', []));
return $manager;
How can I help you explore Laravel packages today?