PHP code example of desmart / files

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

    

desmart / files example snippets


$app->register('DeSmart\Files\ServiceProvider\LumenServiceProvider');


// config/filesystems.php
return [
    'disks' => [
        'upload' => [
            'driver' => 'local',
            'root'   => public_path('upload'),        
        ],
    ],
];


$file = \Request::file('file');
$source = new \DeSmart\Files\FileSource\UploadedFileSource($file);

// I'm assuming that Manager instance will be injected by Laravel Container
$manager = app('DeSmart\Files\Manager');

// Here we have the FileEntity instance
// File is saved on the filesystem and in the database
$entity = $manager->store($source);

// from here you have save the relation with other entity
// this is just example!

$user->addFile($entity);
$user->save();


$file = new FileEntity; // $file should be obtained in different way (e.g through a relation)

$manager = app('DeSmart\Files\Manager');
$manager->remove($file);
bash
php artisan vendor:publish
php artisan migrate
bash
cp vendor/desmart/files/database/migrations/* database/migrations/
cp vendor/desmart/files/config/desmart_files.php config/desmart_files.php
php artisan migrate