PHP code example of laravel-persona / monorepo

1. Go to this page and download the library: Download laravel-persona/monorepo 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/ */

    

laravel-persona / monorepo example snippets


use Illuminate\Support\Facades\Schedule;

Schedule::command('persona:clean-orphans')->dailyAt('03:00');

namespace App\Models;

use Illuminate\Foundation\Auth\User as Authenticatable;
use Persona\Traits\HasPersona;

class User extends Authenticatable
{
    use HasPersona;
}

// Managing contacts...
$user->persona()->addContact('phone', '+1234567890', isPrimary: true);
$user->persona()->verifyContact($contact, $otpCode);

// Updating profile data...
$user->persona()->updateProfile([
    'first_name' => 'Taylor',
    'last_name' => 'Otwell',
    'timezone' => 'America/Chicago',
]);

// Attaching documents...
$document = $user->persona()->addDocument('passport', 'A1234567', [
    'country_code' => 'US'
]);

// Connecting relationships (Canonical Ordering handled automatically)...
$user->persona()->linkTo($otherUser, 'friend');

$footprint = $user->persona()->getFootprint();

echo $footprint['profile']->first_name;
$contacts = $footprint['contacts'];
$documents = $footprint['documents'];

$user->persona()->forgetAll();

$user->delete();

Schedule::command('persona:clean-orphans')->dailyAt('03:00');

use Persona\Traits\HasPersona;

class Customer extends Model
{
    use HasPersona;

    // Retain Persona data even if the Customer record is deleted
    public bool $preservePersonaOnDelete = true;
}
bash
php artisan persona:install
bash
php artisan persona:clean-orphans
php artisan persona:clean-orphans --pretend   # preview only, delete nothing
bash
php artisan persona:clean-orphans --chunk=2500
bash
  php artisan persona:clean-orphans
  # Skipping [Customer] (Preservation enabled)