Laravel Storage::extend 不工作
Laravel Storage::extend not working
我不知道我哪里出错了。我通过 composer 安装 spatie/flysystem-dropbox
来遵循 Laravel 文档,从 Laravel 文档中复制了 DropboxServiceProvider,添加了提供给 config\app.php
、运行 composer dump autoload
但我仍然收到以下错误消息:
PHP error: Undefined index: driver in /***/vendor/laravel/framework/src/Illuminate/Filesystem/FilesystemManager.php on line 112
这里是服务提供商:
<?php
namespace App\Providers;
use Storage;
use League\Flysystem\Filesystem;
use Spatie\Dropbox\Client as DropboxClient;
use Illuminate\Support\ServiceProvider;
use Spatie\FlysystemDropbox\DropboxAdapter;
class DropboxServiceProvider extends ServiceProvider
{
/**
* Perform post-registration booting of services.
*
* @return void
*/
public function boot()
{
Storage::extend('dropbox', function ($app, $config) {
$client = new DropboxClient(
$config['authorizationToken']
);
return new Filesystem(new DropboxAdapter($client));
});
}
/**
* Register bindings in the container.
*
* @return void
*/
public function register()
{
//
}
}
这是我的 config/app/php:
...
/*
* Application Service Providers...
*/
App\Providers\AppServiceProvider::class,
App\Providers\AuthServiceProvider::class,
App\Providers\DropboxServiceProvider::class,
// App\Providers\BroadcastServiceProvider::class,
App\Providers\EventServiceProvider::class,
App\Providers\RouteServiceProvider::class,
...
最后,这是我的 config/filesystems。php:
'dropbox'=>[
'authorizationToken'=>env('DROPBOX_ACCESS_TOKEN')
],
原来我在 config/filesystems/php
中遗漏了驱动程序值,所以它应该是这样的:
'dropbox'=>[
'driver' => 'dropbox', <=== THIS WAS MISSING
'authorizationToken'=>env('DROPBOX_TOKEN')
],
一个好的包可用于使用 dropbox 扩展存储:详细文档:https://github.com/GrahamCampbell/Laravel-Dropbox
steps for use this package :
1 : composer require graham-campbell/dropbox in your cmd window
2 : after this you have to register service provider for laravel dropbox,
go to config/app.php
and add 'GrahamCampbell\Dropbox\DropboxServiceProvider' this in provider array
and 'Dropbox' => 'GrahamCampbell\Dropbox\Facades\Dropbox' this to aliases array
3: now you have to publish pacakge so 'php artisan vendor:publish' run this in your cmd
- this will create dropbox.php file in your config in this file you have to add your credentials
4: here you have two option for connection you can use it according to your choice.
usage :
simple example :
use GrahamCampbell\Dropbox\Facades\Dropbox;
// you can alias this in config/app.php if you like
Dropbox::createFolder('Folder_Name');
// we're done here - how easy was that, it just works!
Dropbox::delete('Folder_Name');
// this example is simple, and there are far more methods available
我不知道我哪里出错了。我通过 composer 安装 spatie/flysystem-dropbox
来遵循 Laravel 文档,从 Laravel 文档中复制了 DropboxServiceProvider,添加了提供给 config\app.php
、运行 composer dump autoload
但我仍然收到以下错误消息:
PHP error: Undefined index: driver in /***/vendor/laravel/framework/src/Illuminate/Filesystem/FilesystemManager.php on line 112
这里是服务提供商:
<?php
namespace App\Providers;
use Storage;
use League\Flysystem\Filesystem;
use Spatie\Dropbox\Client as DropboxClient;
use Illuminate\Support\ServiceProvider;
use Spatie\FlysystemDropbox\DropboxAdapter;
class DropboxServiceProvider extends ServiceProvider
{
/**
* Perform post-registration booting of services.
*
* @return void
*/
public function boot()
{
Storage::extend('dropbox', function ($app, $config) {
$client = new DropboxClient(
$config['authorizationToken']
);
return new Filesystem(new DropboxAdapter($client));
});
}
/**
* Register bindings in the container.
*
* @return void
*/
public function register()
{
//
}
}
这是我的 config/app/php:
...
/*
* Application Service Providers...
*/
App\Providers\AppServiceProvider::class,
App\Providers\AuthServiceProvider::class,
App\Providers\DropboxServiceProvider::class,
// App\Providers\BroadcastServiceProvider::class,
App\Providers\EventServiceProvider::class,
App\Providers\RouteServiceProvider::class,
...
最后,这是我的 config/filesystems。php:
'dropbox'=>[
'authorizationToken'=>env('DROPBOX_ACCESS_TOKEN')
],
原来我在 config/filesystems/php
中遗漏了驱动程序值,所以它应该是这样的:
'dropbox'=>[
'driver' => 'dropbox', <=== THIS WAS MISSING
'authorizationToken'=>env('DROPBOX_TOKEN')
],
一个好的包可用于使用 dropbox 扩展存储:详细文档:https://github.com/GrahamCampbell/Laravel-Dropbox
steps for use this package :
1 : composer require graham-campbell/dropbox in your cmd window
2 : after this you have to register service provider for laravel dropbox,
go to config/app.php
and add 'GrahamCampbell\Dropbox\DropboxServiceProvider' this in provider array
and 'Dropbox' => 'GrahamCampbell\Dropbox\Facades\Dropbox' this to aliases array
3: now you have to publish pacakge so 'php artisan vendor:publish' run this in your cmd
- this will create dropbox.php file in your config in this file you have to add your credentials
4: here you have two option for connection you can use it according to your choice.
usage :
simple example :
use GrahamCampbell\Dropbox\Facades\Dropbox;
// you can alias this in config/app.php if you like
Dropbox::createFolder('Folder_Name');
// we're done here - how easy was that, it just works!
Dropbox::delete('Folder_Name');
// this example is simple, and there are far more methods available