smallworldfs/filemanager-laravel

适用于 Laravel 5.6 的文件管理器

安装: 685

依赖者: 0

建议者: 0

安全: 0

星标: 1

关注者: 1

分支: 41

语言:JavaScript

类型:

v3.0.1 2021-08-09 10:33 UTC

This package is auto-updated.

Last update: 2024-09-19 15:40:54 UTC


README

本包基于: http://github.com/simogeo/Filemanager.git ,我们对其进行了修改以封装,以便在我们的项目中安装。

安装此包后,您还将拥有所有必要的依赖项。

安装

如果您已全局安装 composer,则需要运行

composer require "smallworldfs/filemanager-laravel"

否则,您必须在项目的根目录中有一个 composer.phar 文件才能运行

php composer.phar require "smallworldfs/filemanager-laravel"

注册 Filemanager 提供者

首先,您需要将包提供者添加到 config/app.php 文件中的 laravel providers 数组中。

'providers' => [
    // ...
    Smallworldfs\Filemanager\Providers\FilemanagerProvider::class,
];

配置

此包自动加载/注册 "Gates Policies","Routes","Statics" 等,您无需在项目中做任何操作即可运行。

但是...您必须配置配置变量以确保成功运行并针对您的环境进行自定义。

运行此命令,将包的配置文件(filemanager.php 基础配置文件)复制到 laravel 配置目录,您可以编辑此文件。

php artisan vendor:publish --provider="Smallworldfs\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