PHP code example of aammui / laravel-media

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

    

aammui / laravel-media example snippets


use Aammui\LaravelMedia\Traits\HasMedia;
use Illuminate\Database\Eloquent\Model;
 
class Document extends Model
{
    use HasMedia;
}

$user->addMedia(request()->file);
$user->toCollection('profilePicture')
    ->addMedia(request()->file);
$user->toCollection('profilePicture')
     ->toDisk('public')
    ->addMedia(request()->file);
$user->toCollection('profilePicture')
     ->toDisk('public')
    ->addMedia(request()->file);

$user->addMediaFromUrl('http://example.com/image.jpeg');

$user->setDownloadTrue()
    ->addMediaFromUrl('http://example.com/image.jpeg');

$user->getMedia();
$user->fromCollection('profilePicture')
    ->fromDisk('local')
    ->getMedia();

use Aammui\LaravelMedia\Enum\Responsive;

'responsive'=>[
   'responsive' => [
        Responsive::SM => [
            'w' => 50,
            'h' => 50,
        ],
        Responsive::MD => [
            'w' => 150,
            'h' => 150,
        ],
        Responsive::LG => [
            'w' => 600, // Can define either height or width only.
        ],
    ],
];


use Aammui\LaravelMedia\Facades\Media;
use Aammui\LaravelMedia\Enum\Responsive;

Media::ofSize([Responsive::SM,Responsive::MD])
    ->addMedia(request()->file);

use Aammui\LaravelMedia\Facades\Media; // Use Media facade instead

Media::addMedia(request()->file); // returns Media Object
Media::toCollection('profilePicture')
    ->addMedia(request()->file); // returns Media Object while storing grouping files in profilepicture
Media::toCollection('profilePicture')
    ->toStorage('s3')
    ->addMedia(request()->file); // returns Media Object while storing files in s3

php artisan vendor:publish --provider="Aammui\LaravelMedia\LaravelMediaServiceProvider"
php artisan migrate