PHP code example of datashaman / claude-agent-laravel
1. Go to this page and download the library: Download datashaman/claude-agent-laravel library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
datashaman / claude-agent-laravel example snippets
use DataShaman\Claude\AgentLaravel\Facades\Claude;
// Stream messages from a query
foreach (Claude::query('Explain dependency injection') as $message) {
echo $message->getTextContent();
}
// Get a client with session persistence
$client = Claude::client(['model' => 'opus']);
foreach ($client->send('Hello') as $message) {
echo $message->getTextContent();
}
// List sessions
$sessions = Claude::listSessions();
// Get session history
$messages = Claude::getSessionMessages('session-id');
use DataShaman\Claude\AgentLaravel\Jobs\ClaudeQueryJob;
use DataShaman\Claude\AgentLaravel\Events\ClaudeQueryCompleted;
use DataShaman\Claude\AgentLaravel\Events\ClaudeQueryFailed;
// Dispatch a query as a background job
ClaudeQueryJob::dispatch('Summarize this document');
// With overrides
ClaudeQueryJob::dispatch('Hello', ['model' => 'opus']);
// Listen for results in a listener or EventServiceProvider
// ClaudeQueryCompleted: $event->prompt, $event->response, $event->sessionId, $event->timestamp
// ClaudeQueryFailed: $event->prompt, $event->error, $event->exception