PHP code example of effina / larastitial

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

    

effina / larastitial example snippets


use effina\Larastitial\Http\Middleware\CheckInterstitials;

return Application::configure(basePath: dirname(__DIR__))
    ->withMiddleware(function (Middleware $middleware) {
        $middleware->appendToGroup('web', CheckInterstitials::class);
    })
    // ...

protected $middlewareGroups = [
    'web' => [
        // ... other middleware
        \effina\Larastitial\Http\Middleware\CheckInterstitials::class,
    ],
];

dd(app('router')->getMiddlewareGroups()['web']);

use effina\Larastitial\Models\Interstitial;

Interstitial::create([
    'name' => 'welcome-message',
    'title' => 'Welcome!',
    'type' => 'modal',
    'content' => '<p>Thanks for signing up!</p>',
    'trigger_event' => \Illuminate\Auth\Events\Login::class,
    'audience_type' => 'authenticated',
    'frequency' => 'once',
]);

'event_listeners' => [
    \Illuminate\Auth\Events\Login::class,
    \Illuminate\Auth\Events\Registered::class,
],

'frontend' => 'blade', // blade, livewire, inertia, headless

use effina\Larastitial\Facades\Larastitial;

// Get applicable interstitials
$interstitials = Larastitial::getApplicable($user, 'page_load');

// Check if should show
if (Larastitial::shouldShow($interstitial, $user)) {
    // Display interstitial
}

// Mark as viewed
Larastitial::markViewed($interstitial, $user, 'completed');

// Record form response
Larastitial::recordResponse($interstitial, $user, $request->all());

use effina\Larastitial\Traits\HasInterstitials;

class User extends Authenticatable
{
    use HasInterstitials;
}

// Then use:
$user->hasViewedInterstitial($id);
$user->hasCompletedInterstitial($id);
$user->getViewedInterstitialIds();

use effina\Larastitial\Contracts\AudienceCondition;
use effina\Larastitial\Models\Interstitial;

class HasCompletedProfile implements AudienceCondition
{
    public function passes(?Authenticatable $user, Interstitial $interstitial): bool
    {
        return $user && $user->profile_completed_at !== null;
    }
}

'multi_tenant' => [
    'enabled' => true,
    'column' => 'tenant_id',
    'resolver' => \App\Services\TenantResolver::class,
],

use effina\Larastitial\Contracts\TenantResolver;

class TenantResolver implements TenantResolver
{
    public function resolve(): int|string|null
    {
        return auth()->user()?->tenant_id;
    }
}

use effina\Larastitial\Facades\Larastitial;

public function test_interstitial_triggers_on_login(): void
{
    $fake = Larastitial::fake();

    $interstitial = Interstitial::factory()->create();
    $fake->shouldTrigger($interstitial);

    // ... perform action

    $fake->assertTriggered($interstitial->name);
}

use effina\Larastitial\Models\Interstitial;

$interstitial = Interstitial::factory()
    ->modal()
    ->forAuthenticated()
    ->showOnce()
    ->triggeredByEvent(\Illuminate\Auth\Events\Login::class)
    ->create();
bash
php artisan larastitial:install
bash
php artisan vendor:publish --tag=larastitial-config
php artisan vendor:publish --tag=larastitial-migrations
php artisan migrate
bash
php artisan vendor:publish --tag=larastitial-views