1. Go to this page and download the library: Download prelude-so/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/ */
prelude-so / laravel example snippets
use PreludeSo\Laravel\Facades\Prelude;
// Create a phone verification
$verification = Prelude::verification()->create('+1234567890');
// Check verification OTP
$result = Prelude::verification()->check($verificationId, '123456');
// Lookup phone number information
$lookup = Prelude::lookup()->phoneNumber('+1234567890');
// Send transactional message
$message = Prelude::transactional()->send('+1234567890', 'Your verification code is 123456');
// Process webhook data (
use PreludeSo\Sdk\PreludeClient;
class UserController extends Controller
{
public function createVerification(Request $request, PreludeClient $prelude)
{
$phoneNumber = $request->input('phone_number');
$verification = $prelude->verification()->create($phoneNumber);
return response()->json([
'verification_id' => $verification->getId(),
'status' => $verification->getStatus()
]);
}
public function checkVerification(Request $request, PreludeClient $prelude)
{
$verificationId = $request->input('verification_id');
$code = $request->input('code');
$result = $prelude->verification()->check($verificationId, $code);
return response()->json([
'success' => $result->isSuccess(),
'status' => $result->getStatus()->value
]);
}
}
use PreludeSo\Laravel\Http\Requests\SendTransactionalRequest;
class MessageController extends Controller
{
public function sendTransactional(SendTransactionalRequest $request)
{
// All validation is handled automatically
$to = $request->validated('to');
$templateId = $request->validated('template_id');
$options = $request->validated('options');
$metadata = $request->validated('metadata');
// Create options object for SDK if provided
$optionsObject = null;
if ($options) {
$optionsObject = new \PreludeSo\Sdk\Options($options);
}
// Send transactional message using the SDK
$result = Prelude::transactional()->send($to, $templateId, $optionsObject);
return response()->json([
'message_id' => $result->getId(),
'status' => $result->getStatus(),
'sent_at' => $result->getSentAt(),
'recipient' => $to,
'template_id' => $templateId,
]);
}
}
use PreludeSo\Laravel\Traits\InteractsWithPrelude;
class VerificationService
{
use InteractsWithPrelude;
public function createVerification(string $phoneNumber)
{
return $this->createVerification($phoneNumber);
}
public function checkVerification(string $verificationId, string $code)
{
return $this->checkVerification($verificationId, $code);
}
public function lookupPhone(string $phoneNumber)
{
return $this->lookupPhoneNumber($phoneNumber);
}
public function sendMessage(string $phoneNumber, string $message)
{
return $this->sendTransactionalMessage($phoneNumber, $message);
}
}
use PreludeSo\Laravel\Http\Requests\CreateVerificationRequest;
// Use the base class directly with all validation rules
$request = new CreateVerificationRequest();
// Or extend it for custom / Option 2: Override with custom rules
return [
'target.type' => '
use PreludeSo\Laravel\Http\Requests\CheckVerificationRequest;
class VerificationController extends Controller
{
public function checkVerification(CheckVerificationRequest $request)
{
// All validation is handled automatically
$target = $request->validated('target');
$code = $request->validated('code');
// Create target object for SDK
$targetObject = new \PreludeSo\Sdk\Target(
$target['value'],
$target['type']
);
// Check verification using the SDK
$result = Prelude::verification()->check($targetObject, $code);
return response()->json([
'success' => $result->isSuccess(),
'status' => $result->getStatus()->value
]);
}
}
use PreludeSo\Laravel\Http\Requests\PredictOutcomeRequest;
class PredictionController extends Controller
{
public function predictOutcome(PredictOutcomeRequest $request)
{
// All validation is handled automatically
$target = $request->validated('target');
$signals = $request->validated('signals');
$metadata = $request->validated('metadata');
$dispatchId = $request->validated('dispatch_id');
// Create objects for SDK
$targetObject = new \PreludeSo\Sdk\Target(
$target['value'],
$target['type']
);
$signalsObject = new \PreludeSo\Sdk\Signals($signals);
$metadataObject = null;
if ($metadata) {
$metadataObject = new \PreludeSo\Sdk\Metadata($metadata);
}
// Predict outcome using the SDK
$result = Prelude::predictOutcome($targetObject, $signalsObject, $dispatchId, $metadataObject);
return response()->json([
'prediction_id' => $result->getId(),
'outcome' => $result->getOutcome(),
'confidence' => $result->getConfidence()
]);
}
}
use PreludeSo\Laravel\Http\Requests\LookupRequest;
class LookupController extends Controller
{
public function lookupPhoneNumber(LookupRequest $request)
{
// All validation is handled automatically
$phoneNumber = $request->validated('phone_number');
$type = $request->validated('type', []);
// Lookup phone number using the SDK
$result = Prelude::lookup()->lookup($phoneNumber, $type);
return response()->json([
'phone_number' => $result->getPhoneNumber(),
'country_code' => $result->getCountryCode(),
'line_type' => $result->getLineType()?->value,
'caller_name' => $result->getCallerName(),
'flags' => array_map(fn($flag) => $flag->value, $result->getFlags()),
'network_info' => [
'carrier_name' => $result->getNetworkInfo()->getCarrierName(),
'mcc' => $result->getNetworkInfo()->getMcc(),
'mnc' => $result->getNetworkInfo()->getMnc(),
],
'original_network_info' => [
'carrier_name' => $result->getOriginalNetworkInfo()->getCarrierName(),
'mcc' => $result->getOriginalNetworkInfo()->getMcc(),
'mnc' => $result->getOriginalNetworkInfo()->getMnc(),
],
]);
}
}
use PreludeSo\Laravel\Http\Requests\SendFeedbackRequest;
class FeedbackController extends Controller
{
public function sendFeedback(SendFeedbackRequest $request)
{
// All validation is handled automatically
$feedbacks = $request->validated('feedbacks');
// Create feedback objects for SDK
$feedbackObjects = [];
foreach ($feedbacks as $feedback) {
// Create target object
$targetObject = new \PreludeSo\Sdk\ValueObjects\Shared\Target(
$feedback['target']['value'],
$feedback['target']['type']
);
// Create signals object if provided
$signalsObject = null;
if (!empty($feedback['signals'])) {
$signalsObject = new \PreludeSo\Sdk\ValueObjects\Shared\Signals($feedback['signals']);
}
// Create metadata object if provided
$metadataObject = null;
if (!empty($feedback['metadata'])) {
$metadataObject = new \PreludeSo\Sdk\ValueObjects\Shared\Metadata($feedback['metadata']);
}
$feedbackObjects[] = new \PreludeSo\Sdk\ValueObjects\Watch\Feedback(
$targetObject,
$feedback['type'],
$signalsObject,
$feedback['dispatch_id'] ?? '',
$metadataObject
);
}
// Send feedback using the SDK
$result = Prelude::sendFeedback($feedbackObjects);
return response()->json([
'success' => $result->isSuccess(),
'processed_count' => count($feedbackObjects)
]);
}
}