PHP code example of profscode / media-management

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

    

profscode / media-management example snippets


use Profscode\MediaManagement\MediaManagement;

class User extends Model
{
    use MediaManagement;
}

$user = User::find(1);
$user->addMediaFromRequest("profile_picture", "avatars");

[
    "admin_panel" => [
        "width" => 100,
        "height" => 100,
        "webp" => true
    ]
]

$user->addMediaFromUrl("https://domain.com/image.jpg", "gallery");

$conversions = [
    "admin_panel" => [
        "width" => 100,
        "height" => 100,
        "webp" => true
    ]
]
$user->addMediaFromUrl("https://domain.com/image.jpg", "gallery", $conversions);

$user->getMedia();

$media->getFirstMediaUrl($collection = "default");

$media->getFirstMediaUrl($collection , 'admin_panel');

$user->getFirstMediaUrl("avatars", "admin_panel");