PHP code example of hxm / media-encrypt

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

    

hxm / media-encrypt example snippets


    use Illuminate\Database\Eloquent\Model;
    use HXM\MediaEncrypt\Contracts\CanMediaEncryptInterface;
    use HXM\MediaEncrypt\Traits\HasMediaEncrypt;
    
    class OnlineRequest extends Model implements CanMediaEncryptInterface
    {
        use HasMediaEncrypt;
        #...
    }
    
    

    use Illuminate\Database\Eloquent\Model;
    use HXM\MediaEncrypt\Contracts\CanMediaEncryptInterface;
    use HXM\MediaEncrypt\Traits\HasMediaEncrypt;
    use HXM\MediaEncrypt\Casts\MediaEncryptCast;
    use HXM\MediaEncrypt\Casts\MultiMediaEncryptCast;
    
    class DemoModel extends Model implements CanMediaEncryptInterface
    {
    use HasMediaEncrypt;
    
        protected $appends = ['baseData', 'media', 'media_multi'];
   
        protected $casts = [
            #...
            'baseData' => MediaEncryptCast::class,
            'media' => MediaEncryptCast::class,
            'media_multi' => MultiMediaEncryptCast::class,
        ];
        #...
    }


    

    $model = Demo::first();
   
    $model->baseData = [
        'row' => 1, 
        'column' => 2, 
   ];
   
    $model->media = request()->file('file');
   
    $model->media_multi = [
        'file1' => request()->file('file1'),
        'file2' => request()->get('file2'),
    ];
    $model->save();
    

    $model = Demo::first();
   
   dump($model->baseData);
   #@return: instance  HXM\MediaEncrypt\Models\MediaEncrypt
   
   dump($model->baseData->toAray());
    #@return: array:2 [
    #   'row' => 1
    #   'column' => 2
    #   ]
   
    dump($model->media->toUrl());
    #@return: https://baseUrl/encrypt_media/4f03a151-14a9-4234...
    dump($model->media_multi->decrypt());
    #@return: array:2 [
    #   'file1' => https://baseUrl/encrypt_media/4f03a151-14a9-4234...
    #   'file2' => data:image/jpg;base64,/9j/4QAYRXh.........
    #   ]
    

    protected $appends = ['baseData', 'media', 'media_multi'];
    
bash
    php artisan vendor:publish --provider="HXM\MediaEncrypt\MediaEncryptServiceProvider" --tag="media-encrypt-config"
    
bash
   php artisan migrate