This package deals with the operations that occur on files,
such as uploading, updating, fetching, or deleting a file.
composer required ost/laravel-file-manager
php artisan vendor:publish --provider="OST\LaravelFileManager\LaravelFileManagerServiceProvider"
created files
config/laravel_file_manager.php
database/migrations/create_files_table.php
php artisan migrate
1- The default disk is [public]
2- You can change disk from .env by change FILESYSTEM_DISK=public
You can upload one or more file
FileManager::setRequest($request)
->setUserId(1)
->setModelName(User::class)
->setFilePath('/user/1/images')
->uploadFile();
You can update the files by passing the files that you want to upload in the request and passing the urls of the files that you want to update to be deleted from storage
FileManager::setRequest($request)
->setUserId(1)
->setModelName(User::class)
->setFilePath('/user/1/images')
->updateFileByUrl(['url1','url2']);
You can update the files by passing the files that you want to upload in the request and passing the paths of the files that you want to update to be deleted from storage
FileManager::setRequest($request)
->setUserId(1)
->setModelName(User::class)
->setFilePath('/user/1/images')
->updateFileByPath(['path1','path2']);
FileManager::deleteFileByUrl(['url1','url2'],user_id);
You can pass file paths directly
FileManager::deleteFileByPath(['path1','path2'],user_id);
We do this to enable you to create relationships between tables
FileManager::setRequest($request)
->setModelName() // like => Post::class,Message::class
->setModelId() // like => post_id , message_id
FileManager::setRequest($request)
->setMaxFileSizeKB(8000)
FileManager::setRequest($request)
->setDisk(disk_name)
FileManager::setRequest($request)
->setAllowedExtensions('jpg,png,mp4')
default value for => file_key: 'file'
FileManager::setRequest(request: $request,file_key: 'file',file_is_required: true)
default value for => file_is_required: true change to false
FileManager::setRequest(request: $request,file_key: 'file',file_is_required: false)
You can get file url and mime type or only url for file by passing file path
FileManager::getUrl('user/1/images/YFSCBjbOCRQ7At7J7uX4cihDcZkf7j.png',true);
The return result => { "url": "http://127.0.0.1:8000/storage/user/1/images/YFSCBjbOCRQ7At7J7uX4cihDcZkf7j.png", "type": "png" }
You can encrypt file path but you must to create new disk in filesystem because public disk not with encrypted url To enable this feature
'encrypted_url'=>true
'disks' => [
'disk_name' => [
'driver' => 'local',
'root' => storage_path('app/disk_name'),
'url' => env('APP_URL').'/disk_name',
],
]
FILESYSTEM_DISK=disk_name
When get File Url ,the returned url like this:
{
"url": "http://127.0.0.1:8000/disk_name/eyJpdiI6IktKVlRTOENwUnJ5a3VTOG5CNzJsYVE9PSIsInZhbHVlIjoiY25wbEZlYUsxeEhNUXdhWnBSZHgwNlhwRzk1UDJXY0MyTyt4R1NqQjdDS1owRk4vTFdqQWFQU0d3U2h2Z1FBK0Y0TVZCazBRWFNpR2xwOTlpMHBwS2c9PSIsIm1hYyI6IjdjMDgwYTUzOTcxYjMyNWQ2Y2UwNTI5MDI5NmQ0ZjA5YTA0YzU2NjgxMjAxZGZmN2I2YjU5YTMzMjRiMWRkNjMiLCJ0YWciOiIifQ==",
"type": "png"
}
\OST\LaravelFileManager\Models\File::
Change value from true to false
'get_file_route'=>false
Add Route in routes/web to receive request
Route::get('/storage/' . '{path}', function ($path) {
return \OST\LaravelFileManager\FileManager::getFileByRoute($path,$disk,false)
});