PHP code example of inlayphp / media-spatie

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

    

inlayphp / media-spatie example snippets


use Illuminate\Database\Eloquent\Model;
use Spatie\MediaLibrary\HasMedia;
use Spatie\MediaLibrary\InteractsWithMedia;

final class Post extends Model implements HasMedia
{
    use InteractsWithMedia;
}

use Inlay\MediaSpatie\MediaBridge;

$media = app(MediaBridge::class)->attach(
    subject: $post,
    asset: $asset,
    collection: 'hero',
    customProperties: ['alt' => 'Mountain at sunrise'],
    manipulations: ['thumb' => ['width' => 480]],
    conversionsDisk: 'public',
    generateConversions: true,
);

use Inlay\Media\Enums\MediaVisibility;

$asset = app(MediaBridge::class)->ingest(
    media: $spatieMedia,
    folder: $optionalFolder,
    visibility: MediaVisibility::Private,
);
bash
vendor/bin/pest tests/MediaSpatieTest.php