dev-master
9999999-devConnector for Laravel with Google Drive API
GNU
The Requires
0.0.2
0.0.2.0Connector for Laravel with Google Drive API
GNU
The Requires
0.0.1
0.0.1.0Connector for Laravel with Google Drive API
GNU
The Requires
Wallogit.com
2017 © Pedro Peláez
Connector for Laravel with Google Drive API
0.0.2, (*1)
Make sure you have already installed laravel >= 5.2.*, (*2)
Then, install package via composer, (*3)
composer require "smadia/laravel-google-drive-connector:0.0.*"
, (*4)
Register Facade in config/app.php, (*5)
'aliases' => [
.....
'LGD' => Smadia\LaravelGoogleDrive\Facades\LaravelGoogleDrive::class
.....
]
Register ServiceProvider in config/app.php, (*6)
'providers' => [
.....
Smadia\LaravelGoogleDrive\Providers\LaravelGoogleDriveServiceProvider::class
.....
]
You can create your own Facade and ServiceProvider manually, and then register it., (*7)
Before using package, make sure you have added new disk in config/filesystem.php, (*8)
'disks' => [
// ...
'googledrive' => [
'driver' => 'googledrive',
'clientId' => env('GOOGLE_DRIVE_CLIENT_ID'),
'clientSecret' => env('GOOGLE_DRIVE_CLIENT_SECRET'),
'refreshToken' => env('GOOGLE_DRIVE_REFRESH_TOKEN'),
'folderId' => env('GOOGLE_DRIVE_FOLDER_ID'),
],
// ...
],
Then, you should add new field in .env files, (*9)
FILESYSTEM_CLOUD=googledrive GOOGLE_DRIVE_CLIENT_ID=xxx.apps.googleusercontent.com GOOGLE_DRIVE_CLIENT_SECRET=xxx GOOGLE_DRIVE_REFRESH_TOKEN=xxx GOOGLE_DRIVE_FOLDER_ID=null
How do I get the Google Drive API ? Follow these links :, (*10)
You can use LGD Facade in non-object file, such as routes/web.php, blade file. Below is the example usage in non-object file, (*11)
LGD::dir('mydir')->ls()->toObject();
If you are using the Facade in object context, you should use the Facade in Smadia\LaravelGoogleDrive\Facades\LaravelGoogleDrive after the namespace declaration like below, (*12)
<?php namespace App\User; // other use declaration use Smadia\LaravelGoogleDrive\Facades\LaravelGoogleDrive; // other use declaration
After that, you can use LaravelGoogleDrive facade instead than LGD like below, (*13)
LaravelGoogleDrive::ls()->toArray()
To use it only with LGD keyword, you can use as in use declaration like code below, (*14)
<?php namespace App\User; // other use declaration use Smadia\LaravelGoogleDrive\Facades\LaravelGoogleDrive as LGD; // other use declaration
LGD::ls()->toArray()
LGD::dir('mydir')->ls()->toArray()
Index is started from 0 (zero), (*15)
LGD::dir('mydir, 2)->ls()->toArray()
LGD::dir('mydir')->file('youfile', 'txt')->name
LGD::dir('mydir')->file('yourfile', 'txt', 2)->name
Below is the list of file's property which you can get by adding ->(property) after file() method, (*16)
To filter the list contents of directory, you can use filter() method, (*17)
LGD::ls(function($ls) {
return $ls->where('type', '=', 'dir'); // another option of 'type' is 'file'
})->toArray();
These are some example to store file in Google Drive, (*18)
LGD::put('hello.txt', 'Hello World !');
If you want store the uploaded file in your controller, you can use this one, (*19)
LGD::put('hello.txt', file_get_contents($request->file('file')->getRealPath()));
If you want the name is same with the orginal uploaded file, you can assign the $request->file() as parameter, (*20)
LGD::put($request->file('file'));
Below is optional method to your directory, (*21)
| Method | Usage | Description |
|---|---|---|
ls($filter = null) |
Get the list contents of the current directory | This method will return the Smadia/GoogleDriveLaravel/ListContent Class. $filter is a closure which return the $filter itself |
delete() |
Delete the current directory | - |
rename($newname) |
Rename the current directory | This method will return back the DirectoryHandler Class |
put($filename, $contents = null) |
Put a new file to the current directory | $contents can be null if the $filename is instance of FileHandler class. This method will return the FileHandler class of the created file. $filename can assign with UploadedFile class ($request->file() in Laravel) |
file($filename, $extension, $index = 0) |
Get the specified file | This method will return the FileHandler class |
isExist() |
Check is the directory exist | Return boolean type |
mkdir($dirname) |
Make a new directory inside the current directory | This method will return the DirectoryHandler class of the created directory |
dir($dirname, $index = 0) |
Go to specified directory | This method will return the DirectoryHandler class of the requested directory with certain index (default is 0) |
parent() |
Get the parent directory | This method will return the DirectoryHandler class |
| Method | Usage | Description |
|---|---|---|
rename($newname) |
Rename the current file | This method will return the same FileHandler class |
delete() |
Delete the current file | This method will not delete all files with the same name in the same level of directory |
isExist() |
Check whether the file is exist | - |
getDir() |
Get the directory where the file is located | This method will return the DirectoryHandler class |
show() |
Show the file in browser. Only work for jpeg, jpg, png, gif, and svg file extension | - |
download() |
Give a download response | - |
| Method | Usage | Description |
|---|---|---|
toArray() |
Get list contents as array | - |
toCollect() |
Get list contents as Laravel's collection | - |
toObject() |
Get list contents as array which contains FileHandler or DirectoryHandler as it's member | - |
dir($dirname, $index = 0) |
Get the directory where the file is located | This method will return the DirectoryHandler class |
file($filename, $extension, $index = 0) |
Get the specific file name and extension | This method will return the FileHandler class |
filter($filter) |
Get the directory where the file is located | This method will return the DirectoryHandler class. $filter is a closure which return the $filter itself |
getAllProperties() |
Get all properties of a file or directory | This method will return all properties in array |
Connector for Laravel with Google Drive API
GNU
Connector for Laravel with Google Drive API
GNU
Connector for Laravel with Google Drive API
GNU