dreams / filemanager
Laravel 5.6 的文件管理器
v1.0.2
2020-10-29 11:55 UTC
Requires
- php: >=7.1.3
- intervention/image: ^2.4
- laravel/framework: >=5.6
This package is not auto-updated.
Last update: 2024-09-27 06:49:46 UTC
README
此包基于: http://github.com/simogeo/Filemanager.git,我们对它进行了修改以封装,使其能够在我们的项目中独立安装。
安装此包后,您也将拥有所有必要的依赖项来运行。
安装
如果您已全局安装了 composer,则需要运行
composer require "dreams/filemanager"
否则,您必须在项目的根目录中有一个 composer.phar 文件才能运行
php composer.phar require "dreams/filemanager"
注册 Filemanager 提供者
首先,您需要将包提供者添加到 config/app.php 文件中的 Laravel 提供者数组中。
'providers' => [ // ... Dreams\Filemanager\Providers\FilemanagerProvider::class, ];
配置
此包会自动加载/注册“权限策略”、“路由”、“静态资源”等,您不需要在项目中做任何额外的工作。
但是...您必须配置配置变量以使其成功运行,并根据您的环境进行自定义。
运行此命令,包会将(filemanager.php 基础配置文件)复制到 Laravel 配置目录,您可以对此文件进行编辑。
php artisan vendor:publish --provider="Dreams\Filemanager\Providers\FilemanagerProvider"
只有一个文件,太棒了!!
文件管理器配置文件
这是配置文件,您可以看到一个带有限制用户访问文件管理器的角色示例的注释。
<?php return [ // Domain of your project or one domain custom for filemanager 'domain' => env('APP_URL', 'your.domain.com'), // Prefix for url group 'prefix' => 'file-manager', // Folder to store files, normally behind of laravel public dir // Always folder tree must be start with /filemanager/userfiles/ // Example custom folder: /filemanager/userfiles/myfolder 'public_path' => '/filemanager/userfiles/', // Disable your authentication middleware if needs 'middlewares' => ['web', 'auth'], // Activate also, if you need limit user access with roles // AccessRoles Example => 'can:access-filemanager,\admin|oneRole|otherRole|anotherRole' //'middleware_access' => 'can:access-filemanager,\oneRole', // Configure to work with middleware_access, permit access to the first role of user //'roles_path' => [ // //'admin' => '/filemanager/', Equals that public_path is the base dir to other roles // 'oneRole' => '/filemanager/oneRole', // 'otherRole' => '/filemanager/otherRole', // 'anotherRole' => '/filemanager/anotherRole', //], ];
要使用角色,您需要在数据库中创建具有以下结构的角色表
UserTable
- id
- name
- email
- ... (another fileds you need)
RolesTable
- id
- name*
- ... (another fileds you need)
UserRolesTable
- id
- user_id
- role_id
* (role_name is necessary for limit access in the filemanager config file)
然后,您可以通过模型上的 Eloquent 关系访问用户角色
> UserModel::class public function roles() { return $this->belongsToMany(RoleModel::class); } public function hasAnyRole(array $roles) { return null !== $this->roles()->whereIn('name', $roles)->first(); } public function hasRole($role) { return null !== $this->roles()->where('name', $role)->first(); } > RoleModel::class public function users() { return $this->belongsToMany(UserModel::class); }
要激活用户访问,您需要配置配置文件的中间件属性
// Activate also, if you need limit user access with roles // AccessRoles Example => 'can:access-filemanager,\admin|oneRole|otherRole|anotherRole' 'middleware_access' => 'can:access-filemanager,\oneRole', // Configure to work with middleware_access, permit access to the first role of user 'roles_path' => [ //'admin' => '/filemanager/', Equals that public_path is the base dir to other roles 'oneRole' => '/filemanager/oneRole', 'otherRole' => '/filemanager/otherRole', 'anotherRole' => '/filemanager/anotherRole', ],
注意1:如果您只需要一个用户访问,只需创建一个管理员角色
注意2:如果用户有多个角色,仅使用第一个用户角色
注意3:如果您未指定 public_path,它将使用 /filemanager/
注意4:如果您未指定 roles_path,它将使用 public_path