PHP code example of donia-shaker / media-library

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

    

donia-shaker / media-library example snippets


'default_image_format' => 'webp',

use DoniaShaker\MediaLibrary\MediaController;

$media_controller = new MediaController();

$media_controller->saveImage($model, $model_id, $file, $format, $maxWidth, $maxHeight, $quality);

$media_controller->saveTempImage($model, $model_id, $file);

$media_controller->convertTempImage($model, $model_id, $media->id);

$media_controller->deleteTemp();

$media_controller->audio($model, $model_id, $file);

$media_controller->video($model, $model_id, $file);

$media_controller->uploadFile($model, $model_id, $file);

'private'

$media_controller->saveImage($model, $model_id, $file, $format, $maxWidth, $maxHeight, $quality, 'private');

$media_controller->saveImage('order', $order->id, $file, null, 1600, 1600, 75, 'private');

$media_controller->uploadFile($model, $model_id, $file, 'private');

$media_controller->uploadFile('order_receipt_invoice', $order->id, $file, 'private');

$media_controller->audio($model, $model_id, $file, 'private');

$media_controller->video($model, $model_id, $file, 'private');

'privateAuthGuards' => env('MEDIA_PRIVATE_AUTH_GUARDS', 'sanctum'),

$guards = explode(
    ',',
    config('media.privateAuthGuards', 'sanctum')
);

foreach ($guards as $guard) {
    $user = Auth::guard(trim($guard))->user();

    if ($user) {
        return $user;
    }
}

$media->url;

'image' => $media->url,

$media->thumb_url;

use DoniaShaker\MediaLibrary\Rules\SquareImageRule;

'file' => [..., new SquareImageRule],
shell
php artisan vendor:publish --tag=media-library-migrations
php artisan vendor:publish --tag=media-library-config
text
config/media.php
shell
php artisan migrate
text
https://example.com/api/media/private/10?auth_id=1&signature=...
text
https://example.com/api/media/private/10?auth_id=1&thumb=1&signature=...