1. Go to this page and download the library: Download whilesmart/eloquent-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/ */
whilesmart / eloquent-files example snippets
return [
'disk' => 'public', // Storage disk
'upload_path' => 'uploads', // Base path for uploads
'max_size' => 5120, // Max file size in KB (5MB)
'allowed_mimes' => 'image', // Allowed mime types
'register_routes' => true, // Auto-register routes
'route_prefix' => 'api', // Route prefix
'route_middleware' => ['api', 'auth:sanctum'],
];
use Whilesmart\Files\Traits\HasFiles;
class User extends Authenticatable
{
use HasFiles;
}
use Whilesmart\Files\Models\File;
// Get user's files
$files = File::ownedBy($user)->get();
// Delete a file (removes from storage and database)
$file->deleteFile();
// Check ownership
if ($file->isOwnedBy($user)) {
// ...
}