khoanguyenme's avatar

Add new Adapter to Laravel Filesystem

I want to use replicate adapter as my default filesystem in L5. (local as main storage and Amazon S3 as a backup service). Is there anyway to do this with L5 filesystem ?

http://flysystem.thephpleague.com/adapter/replicate/

Edit: It looks like Laravel only have 2 cloud filesystem out of box : Rackspace and S3. I did find this article http://www.jernejsila.com/zapisi/2014/09/10/add-dropbox-filesystem-driver-laravel-5-project/

But I have to edit framework? Is there any easier way to add new file system driver to L5?

0 likes
7 replies
usman's avatar
usman
Best Answer
Level 27

There is no need for editing the core files of the framework. You can follow these steps to acheive this:

  • Extend the Illuminate\Filesystem\FilesystemManager and implement your driver creation strategy i.e createXyzDriver().
  • Extend the base Illuminate\Filesystem\FilesystemServiceProvider and override the registerManager method to return your custom instance of the manager.

Usman.

2 likes
khoanguyenme's avatar

@JohnRivs Thank you but I means to do it in L5 ways.

@usman Thank you. One thing you forgot is replace 'Illuminate\Filesystem\FilesystemServiceProvider' with my own extends class in config/app.php. I'm trying to make it work with replicate adapter.

1 like
JohnRivs's avatar

@khoanguyenme If you read the examples, it pretty much the L5 way. It does the preparation and configuration leg work for you. The API is the same you would use.

Note that the connection class returned will always be an instance of a class that implements \League\Flysystem\FilesystemInterface which will be \League\Flysystem\Filesystem by default.

1 like
khoanguyenme's avatar

@JohnRevis : Accutally, I mean Laravel 5 Filesystem. It's a abstract class of Flysystem. I like the concept that in the future, I didn't want to replicate file anymore. The only thing I need to change is a config, not my code.

Please or to participate in this conversation.