https://github.com/skycoder026/laravel-filesaver
Laravel Filesaver
https://github.com/skycoder026/laravel-filesaver
fileupload google-drive-fileupload local-storage-fileupload
Last synced: 5 months ago
JSON representation
Laravel Filesaver
- Host: GitHub
- URL: https://github.com/skycoder026/laravel-filesaver
- Owner: skycoder026
- Created: 2021-12-08T16:36:56.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2022-12-03T18:03:17.000Z (over 3 years ago)
- Last Synced: 2025-10-31T02:35:07.090Z (8 months ago)
- Topics: fileupload, google-drive-fileupload, local-storage-fileupload
- Language: PHP
- Homepage:
- Size: 12.7 KB
- Stars: 4
- Watchers: 1
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# Description [](http://travis-ci.org/jeresig/jquery.hotkeys)
**Laravel Filesaver** is a media saver package, that can help you to stored any kind of media file. And it is very easy to use and install.
This is a small package to easy and simplify your code.
**Speciality** it will automatically save file/image name with actual path into your database
## Installation Process
```bash
composer require skycoder/laravel-filesaver
```
## Uses
Open your controller from where you want to store your media file and use this piece of line code into the method.
```php
$fileSaver = new Filesaver();
$fileSaver->upload_file($request->form_variable, $modelName, 'database_fieldname', 'base-path');
```
or
```php
(new Filesaver())->upload_file($request->file_variable, $modelName, 'database_fieldname', 'base-path');
```
In both case you shoud import class `use Skycoder\LaravelFilesaver\Filesaver;` top of the class
## Example Code
```php
$request->name,
'email' => $request->email
]);
(new Filesaver())->upload_file($request->image, $user, 'profile-pic', 'user-profile-pic');
return $user->refresh();
}
}
```
## Configuration for Google Drive
Follow the link to get Google Drive Credential if you don't have
After that you should install a google drive package,
`composer require nao-pon/flysystem-google-drive`
If need add `App\Providers\GoogleDriveServiceProvider::class,` to providers array into `config/app.php`
And then add this array into `config/filesystems.php`
```php
'google' => [
'driver' => 'google',
'clientId' => env('GOOGLE_CLIENT_ID'),
'clientSecret' => env('GOOGLE_CLIENT_SECRET'),
'refreshToken' => env('GOOGLE_REFRESH_TOKEN'),
'folderId' => env('GOOGLE_DRIVE_FOLDER_ID'),
],
```
And finally add your google drive credential into `.env` file
```env
FILESYSTEM_CLOUD=google
GOOGLE_CLIENT_ID="YOUR_GOOGLE_CLIENT_ID"
GOOGLE_CLIENT_SECRET=YOUR_GOOGLE_CLIENT_SECRET"
GOOGLE_REFRESH_TOKEN="YOUR_GOOGLE_REFRESH_TOKEN"
GOOGLE_DRIVE_FOLDER_ID="YOUR_GOOGLE_DRIVE_FOLDER_ID"
```
After finish your setup you should add one line of code into your controller
```php
(new Filesaver())->uploadFileToGoogleDrive($request->form_file_name, $modelName, 'database_file_name');
```
## More Packages
- User Log