PHP code example of djurovicigoor / lara-files

1. Go to this page and download the library: Download djurovicigoor/lara-files 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/ */

    

djurovicigoor / lara-files example snippets


'providers' => [
    // ...
    DjurovicIgoor\LaraFiles\LaraFilesProvider::class,
];

/*
|--------------------------------------------------------------------------
| Default visibility
|--------------------------------------------------------------------------
|
| public  => Files are accessible through a browser
| private => Files are not accessible through a browser
*/
'visibility'   => 'public',

/*
|--------------------------------------------------------------------------
| Type of files - relations
|--------------------------------------------------------------------------
|
*/
'types' => [
    'file',
    'avatar',
    'thumbnail',
],

$avatar  = $post->avatar
$avatars = $post->avatars

'disks' => [
     'local' => [
        'driver'    => 'local',
        'root'      => storage_path('app'),
     ],
    'public' => [
        'driver'        => 'local',
        'root'          => storage_path('app/public'),
        'url'           => env('APP_URL').'/storage',
        'visibility'    => 'public',
    ],
    'DOSpaces' => [
        'driver'   => 's3',
        'key'      => env('DO_SPACES_KEY' , 'Your spaces key goes here'),
        'secret'   => env('DO_SPACES_SECRET' , 'Your spaces secret goes here'),
        'endpoint' => env('DO_SPACES_ENDPOINT' , 'Your spaces endpoint goes here'),
        'region'   => env('DO_SPACES_REGION' , 'Your spaces region goes here'),
        'bucket'   => env('DO_SPACES_BUCKET' , 'Your spaces bucket goes here'),
        'url'      => env('AWS_URL' , 'https://{BUCKET}.{REGION}.digitaloceanspaces.com/'),
    ],
    's3' => [
        'driver' => 's3',
        'key'       => env('AWS_ACCESS_KEY_ID' , 'Your aws acces key goes here'),
        'secret'    => env('AWS_SECRET_ACCESS_KEY' , 'Your aws secret key goes here'),
        'region'    => env('AWS_DEFAULT_REGION' , 'Your aws default region goes here'),
        'bucket'    => env('AWS_BUCKET' , 'Your aws bucket name goes here'),
        'url'       => env('AWS_URL' , 'https://s3.{REGION}.amazonaws.com/{BUCKET}/'),
    ]
],

use DjurovicIgoor\LaraFiles\Traits\LaraFileTrait;
use Illuminate\Database\Eloquent\Model;

class Post extends Model {
    
    use LaraFileTrait;
    // ...
}

$additionalParameters = [
    'visibility'    => 'public',
    'description'   => 'Lorem ipsum dolor sit amet . . .',
    'author_id'     => $user->id
];

$post = Post::find($id);
$post->uploadHttpFile('local', $request->file('image'), 'thumbnail', $additionalParameters = [])

$post = Post::find($id);
$post->uploadHttpFiles('local', $arrayOfHttpUploadedFiles, 'thumbnail', $additionalParameters = [])

$post = Post::find($id);
$post->uploadBase64File('local', $base64String, 'thumbnail', $additionalParameters = [])

$post = Post::find($id);
$post->uploadBase64Files('local', $arrayOfBase64String, 'thumbnail', $additionalParameters = [])
bash
php artisan vendor:publish --provider="DjurovicIgoor\LaraFiles\LaraFilesProvider"
 bash
$ php artisan migrate