kenarkose/transit
最新稳定版本:2.1.3
Composer 安装命令:
composer require kenarkose/transit
包简介
Easy file uploading and downloading for Laravel 5
README 文档
README
Easy file uploading and downloading for Laravel 5.
Features
- Compatible with Laravel 5
- Clean API for uploading and downloading files
- Automated(optional) validation while uploading files
- Customization options for file storage, model and validation
- Generators for model and migration
- Deleting uploaded files
- A phpunit test suite for easy development
Installation
Installing Transit is simple.
-
Pull this package in through Composer.
{ "require": { "kenarkose/transit": "~2.1" } } -
In order to register Transit Service Provider add
'Kenarkose\Transit\Provider\TransitServiceProvider'to the end ofprovidersarray in yourconfig/app.phpfile.'providers' => array( 'Illuminate\Foundation\Providers\ArtisanServiceProvider', 'Illuminate\Auth\AuthServiceProvider', ... 'Kenarkose\Transit\Provider\TransitServiceProvider', ),
-
In order to persist the uploaded file information, you have to create a migration for the 'Kenarkose\Transit\File\File' model, which is the default model used for database persistence. To do so, use the following command.
php artisan transit:migration
Do not forget to migrate the database when prompted to or after modifying the generated migration file.
-
You may access the services provided by Transit by using the supplied Facades or from the service container.
// Symfony\Component\HttpFoundation\File\UploadedFile $uploadedFile Uploader::upload($uploadedFile); app()->make('transit.upload')->upload($uploadedFile); // Kenarkose\Transit\Contract\Downloadable $fileModel return Downloader::download($fileModel); return app()->make('transit.download')->download($fileModel);
In order to register the Facades add following the facades to the end of
aliasesarray in yourconfig/app.phpfile.'aliases' => array( 'App' => 'Illuminate\Support\Facades\App', 'Artisan' => 'Illuminate\Support\Facades\Artisan', ... 'Downloader' => 'Kenarkose\Transit\Facade\Downloader', 'Uploader' => 'Kenarkose\Transit\Facade\Uploader', ),
-
Finally, you may configure the default behaviour of Transit by publishing and modifying the configuration file. To do so, use the following command.
php artisan vendor:publish
Than, you will find the configuration file on the
config/transit.phppath. Additional information about the options can be found in the comments of this file. All of the options in the config file are optional, and falls back to default if not specified; remove an option if you would like to use the default. -
Please check the tests and source code for further documentation.
Custom Model
You may need a custom model for your case; for instance, when you wish to use Ownable. You can generate a new model for Transit with the following command.
php artisan transit:model
If you do not wish to use the generator, make sure that your model implements Kenarkose\Transit\Contract\Uploadable interface.
Keep in mind that if you would like to use a custom model you should publish the configuration file by using php artisan vendor:publish command and change the class path for model in the configuration file as well. Alternatively you may configure the UploadService on runtime by using the the modelName method. It is required only for UploadService that you register the model name:
Uploader::modelName('Custom\Uploadable\Model'); // or app()->make('transit.upload')->modelName('Custom\Uploadable\Model');
You may use separate models for Upload and Download services as well as deleting files.
But you must implement Kenarkose\Transit\Contract\Uploadable, Kenarkose\Transit\Contract\Downloadable and Kenarkose\Transit\Contract\Deletable interfaces respectively. Furthermore, you may use Kenarkose\Transit\File\Uploadable, Kenarkose\Transit\File\Downloadable and Kenarkose\Transit\File\Deletable traits for providing required functionality to Eloquent models.
License
Transit is released under MIT License.
统计信息
- 总下载量: 793
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 5
- 点击次数: 0
- 依赖项目数: 1
- 推荐数: 1
其他信息
- 授权协议: MIT
- 更新时间: 2015-04-15