<?php

require __DIR__ . '/vendor/autoload.php';

$app = require_once __DIR__ . '/bootstrap/app.php';
$app->make('Illuminate\Contracts\Console\Kernel')->bootstrap();

$user = App\Models\User::find(24);

if ($user) {
    echo "User 24: {$user->name}\n";
    echo "Current portals:\n";
    
    if ($user->portals) {
        foreach ($user->portals as $portal) {
            echo "  - {$portal->name} (ID: {$portal->id})\n";
        }
    } else {
        echo "  No portals assigned\n";
    }
    
    // Test if portals relationship works
    try {
        $portalIds = $user->portals->pluck('id')->toArray();
        echo "\nPortal IDs: " . json_encode($portalIds) . "\n";
    } catch (Exception $e) {
        echo "\n❌ Error accessing portals: " . $e->getMessage() . "\n";
    }
} else {
    echo "User 24 not found\n";
}
