PHP code example of maniaba / asset-connect

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

    

maniaba / asset-connect example snippets


// Add an asset to a user
$asset = $user->addAsset('/path/to/file.jpg')
    ->withCustomProperties([
        'title' => 'Profile Picture',
        'description' => 'User profile picture'
    ])
    ->toAssetCollection(ImagesCollection::class);

// Get all assets for a user
$assets = $user->getAssets();

// Get assets from a specific collection
$images = $user->getAssets(ImagesCollection::class);

// Get the URL to an asset
$url = $user->getFirstAsset(ImagesCollection::class)->getUrl();

// Delete assets from a specific collection
$user->deleteAssets(ImagesCollection::class);

public string $defaultPublicStorage = 'public';
public string $defaultProtectedStorage = 'protected';

public array $storages = [
    'public' => [
        'driver'     => 'local',
        'root'       => WRITEPATH . 'asset-connect/public',
        'public_url' => 'assets/storage',
        'visibility' => 'public',
    ],
    'protected' => [
        'driver'     => 'local',
        'root'       => WRITEPATH . 'asset-connect/protected',
        'visibility' => 'protected',
    ],
];

$asset->withTemporaryFile(static function (string $source): void {
    service('image')
        ->withFile($source)
        ->resize(1200, 900, true)
        ->save(WRITEPATH . 'cache/processed.jpg');
});

$asset->transferToStorage('protected');
$asset->transferToStorage('s3_public', deleteSource: false);
bash
php spark migrate --namespace=Maniaba\\AssetConnect
bash
php spark asset-connect:storage-link