A simple package that provides a new Storage Driver for bunny CDN using their Filesystem Adapter.
composer require itsemon245/laravel-bunny
Add a new entry for disks
in config/filesystems.php
using the following example.
'bunny'=>[
'driver' => 'bunny',
'storage_zone' => env('BUNNYCDN_STORAGE_ZONE', 'my-storage-zone'),# Name of your storage zone
'pull_zone' => env('BUNNYCDN_PULL_ZONE', 'https://random.b-cdn.net'),#Pull Zone URL
'api_key' => env('BUNNYCDN_API_KEY'), # Use one of the password found in the storage zone.
'region' => env('BUNNYCDN_REGION', \Itsemon245\LaravelBunny\Region::DEFAULT),
'root'=> 'my-files',#Optional, all files will be stored under this directory if specified
]
Note
Don't use the api key from your account settings, it does not work. Use one of the passwords found under Storage Zone > FTP & API Access section
Usage is pretty simple.
//Storing file
Storage::disk('bunny')->put('new-file.txt', 'hello-world');
//Retrieving url
$url = Storage::disk('bunny')->url('new-file.txt');# https://random.b-cdn.net/my-files/new-file.txt
You can also skip calling the disk method everytime if you set FILESYSTEM_DISK
to bunny
in you .env
. Then you can do something simple like.
//Storing file
Storage::put('new-file.txt', 'hello-world');
//Retrieving url
$url = Storage::url('new-file.txt');# https://random.b-cdn.net/my-files/new-file.txt
For a full region list, please visit the BunnyCDN API documentation page.
The package also comes with a set of region constants to use
use Itsemon245\LaravelBunny\Region;
# Default
Region::DEFAULT = 'de';
# Europe
Region::FALKENSTEIN = 'de';
Region::STOCKHOLM = 'se';
# United Kingdom
Region::UNITED_KINGDOM = 'uk';
# USA
Region::NEW_YORK = 'ny';
Region::LOS_ANGELAS = 'la';
# SEA
Region::SINGAPORE = 'sg';
# Oceania
Region::SYDNEY = 'syd';
# Africa
Region::JOHANNESBURG = 'jh';
# South America
Region::BRAZIL = 'br';