1. Go to this page and download the library: Download skaisser/laravel-lead 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/ */
skaisser / laravel-lead example snippets
return [
// The model class that represents leads
'lead_model' => App\Models\Lead::class,
// Storage layers configuration
'use_session' => true,
'use_cookies' => true,
'cookie_name' => 'lead_id',
'cookie_duration' => 525600, // 365 days
// Encryption settings
'encryption_enabled' => true,
// Cache configuration
'cache_prefix' => 'lead_',
'cache_ttl' => 1800, // 30 minutes
];
use Skaisser\LaravelLead\Facades\LeadPersistence;
// Store a lead
$lead = Lead::create(['name' => 'John Doe', 'email' => '[email protected]']);
LeadPersistence::storeLead($lead);
// Retrieve current lead (with automatic fallback)
$currentLead = LeadPersistence::getCurrentLead();
// Check if a lead exists
if (LeadPersistence::hasStoredLead()) {
// Lead exists in storage
}
// Clear stored lead
LeadPersistence::clearStoredLead();
// Save lead data progressively (creates or updates)
$leadData = [
'name' => request('name'),
'email' => request('email'),
'phone' => request('phone'),
'country_code' => request('country_code'),
'query_data' => request()->query(), // UTM parameters, etc.
];
$lead = LeadPersistence::saveLead($leadData);
// Update existing lead
$existingLead = LeadPersistence::getCurrentLead();
$updatedLead = LeadPersistence::saveLead($newData, $existingLead);
use Skaisser\LaravelLead\Services\PhoneFormatter;
$formatter = app(PhoneFormatter::class);
// Format a phone number
$formatted = $formatter->format('11999999999', '+55'); // (11) 99999-9999
// Validate a phone number
$isValid = $formatter->isValid('1234567890', '+1');
// Get international format
$international = $formatter->toInternational('11999999999', '+55'); // +55 11 999999999
// Add custom format for a country
$formatter->addCustomFormat('33', function($numbers) {
// Custom French formatting
return preg_replace('/(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/', '$1 $2 $3 $4 $5', $numbers);
});
// In your Livewire component
$this->dispatch('store-lead', ['leadId' => $encryptedLeadId]);
$this->dispatch('check-local-storage');
$this->dispatch('clear-lead');
// app/Models/Lead.php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Lead extends Model
{
protected $fillable = [
'name', 'email', 'phone', 'company',
'country_code', 'query_data', 'accepted_terms'
];
protected $casts = [
'query_data' => 'array',
'accepted_terms' => 'boolean',
];
}