PHP code example of marque / trove

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

    

marque / trove example snippets


use Marque\Trove\Concerns\HasRoles;
use Marque\Trove\Contracts\UserInterface;

class User extends Authenticatable implements UserInterface
{
    use HasRoles;
}

use Marque\Bloodhound\Concerns\HasTrackerStats;

class User extends Authenticatable implements UserInterface
{
    use HasRoles, HasTrackerStats;
}

$user->isAdmin();
$user->isModerator();
$user->isUploader();
$user->hasRoleAtLeast(Role::Moderator);

use Marque\Trove\Contracts\TrackerStatsInterface;

$tracker = app()->bound(TrackerStatsInterface::class)
    ? app(TrackerStatsInterface::class)
    : null;                                   // no tracker installed

$stats = $tracker?->statsFor($user);         // TrackerStats: uploaded, downloaded, seedtime, ratio
$key = $tracker?->announceKeyFor($user);     // the key for the user's announce URL
$tracker?->regenerateAnnounceKey($user);     // issue a new one; the old stops working

$stats->ratio;                // float, unrounded — or null, meaning INFINITE (nothing downloaded)
$stats->hasInfiniteRatio();   // say it without relying on the null

use Marque\Trove\Contracts\TorrentServiceInterface;

$service = app(TorrentServiceInterface::class);

// List with pagination and search
$torrents = $service->list(perPage: 25, search: 'ubuntu');

// Upload a .torrent file (extracts info_hash, size, file count automatically).
// The info_hash is sha1 of the info dictionary's original bytes, as clients compute it.
$torrent = $service->createFromUpload($file, $user, 'Ubuntu 24.04', 'Official ISO');

// Find by info hash. Unscoped: it ignores min_role. Meant for internal lookups, so check
// the policy before showing its result to a user.
$torrent = $service->findByInfoHash('a1b2c3d4...');

// Update
$service->update($torrent, ['name' => 'New Name']);

// Delete (removes stored file too)
$service->delete($torrent);

use Marque\Trove\Services\TorrentFileService;

$files = app(TorrentFileService::class);

// Before storing: refusals (each naming the fix) and warnings.
$inspection = $files->inspect($content);
$inspection->refused();     // bool
$inspection->refusals;      // list<string>
$inspection->warnings;      // list<string>

// For a download: this user's .torrent, with a link back to the torrent's page.
$body = $files->forDownload($torrent, $user, route('torrents.show', $torrent));

use Livewire\Livewire;
use Marque\Trove\Registry\DashboardPanel;
use Marque\Trove\Registry\DashboardPanelRegistry;

public function boot(): void
{
    Livewire::component('acme-stats-panel', AcmeStatsPanel::class);

    $this->app->make(DashboardPanelRegistry::class)->register(new DashboardPanel(
        identifier: 'acme-stats',
        label: 'Acme Stats',
        component: 'acme-stats-panel',
        position: 35,
        // Per request, against the signed-in user. Omit it to show the panel to
        // everyone who reaches the dashboard.
        visible: fn (?object $user): bool => $user !== null && $user->widgets()->exists(),
    ));
}

$torrent->update(['min_role' => Role::Uploader]);

// Everything the current user may see:
$torrents = $service->list();

// Explicitly as a guest:
$torrents = $service->list(viewer: ViewerScope::guest());
bash
php artisan vendor:publish --tag=trove-config
php artisan migrate
bash
php artisan trove:check-info-hashes
bash
php artisan vendor:publish --tag=trove-migrations