PHP code example of mirafive / sdk-laravel

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

    

mirafive / sdk-laravel example snippets


use MiraFive\Laravel\Facades\Mira;

public function store(Request $request)
{
    $user = User::create($request->validated());

    Mira::track('signup', userId: (string) $user->id, properties: ['plan' => $user->plan]);

    return redirect()->route('dashboard');
}

use Illuminate\Auth\Events\Login;
use Illuminate\Support\Facades\Event;
use MiraFive\Laravel\Facades\Mira;

// AppServiceProvider::boot()
Event::listen(Login::class, fn (Login $event) => Mira::forUser($event->user)->identify(['plan' => $event->user->plan]));

$flags = Mira::flags()->for(
    userId: (string) $user->id,
    properties: ['plan' => $user->plan],
    consent: ['experiments' => true, 'targeting' => false],
    optedOut: Mira::optedOut($request),   // Sec-GPC: 1 or DNT: 1
);

$flags->enabled('new-checkout');           // bool
$flags->variant('pricing-test');           // ?string
$flags->config('limits', ['max' => 3]);    // the variant's value

use MiraFive\Laravel\Facades\Mira;

it('tracks the signup', function () {
    $mira = Mira::fake();

    $this->post('/register', [...])->assertRedirect();

    $mira->assertTracked('signup');
    $mira->assertTracked('signup', fn (array $event) => $event['properties']['plan'] === 'pro');
    $mira->assertTracked('signup', 1);                 // exactly once
    $mira->assertNotTracked('refund');
    $mira->assertIdentified((string) $user->id);
});

it('stays quiet', function () {
    Mira::fake()->assertNothingTracked();              // nothing tracked, sent or identified
});
bash
php artisan vendor:publish --tag=mirafive-config
bash
php artisan mirafive:check
blade
<head>
    @mirafiveFlags(['userId' => auth()->id(), 'properties' => ['plan' => auth()->user()?->plan]])
    @mirafiveScript(['data-flags' => true])
</head>