如何在 Laravel 中上传图片到对应的租户?

问题描述 投票:0回答:2

我第一次使用多租户,并且我有多个租户,问题是我不知道如何上传到存储到相应的租户图像。

例如: 租户1: 上传您的公司徽标

租户2: 上传您自己的公司徽标

我目前正在与租户 59138 合作(storage/app/tenancy/tenants/59138/[此处添加 图像文件夹]

配置文件系统

'tenancy' => [
     'driver' => 'local',
     'root' => storage_path('app/tenancy/tenants/'),
],

控制器

public function storeImage(Request $request){
     //dd($request->all());
     if ($request->file('logo')) {
        $fileLogo = $request->file('logo');
            
        $path = Storage::disk('tenancy')->put('public',$fileLogo);
        
     }
}
laravel multi-tenant
2个回答
3
投票
public function uploadFile(Request $request){

    $File = $request->file('data'); 

    //First Parameter is the Folder Name and Second Parameter is the File Object
    $stored = \Storage::disk('public')->put("your_folder_name", $File);
    $url = tenant_asset($stored);
    return response()->json(['success' =>$url], 200);

}

0
投票

如果有人使用版本3

tenant_asset() 使用此控制器在验证文件是否有效后返回任何文件的响应

/vendor/stancl/tenancy/src/Controllers/TenantAssetsController.php

我面临该功能的问题,它会将我重定向回来或由于中间件而抛出错误,他们正在使用这个中间件

 public static $tenancyMiddleware = 'Stancl\Tenancy\Middleware\InitializeTenancyByDomain';

在我使用相同的自定义控制器更改为该控制器后,它就可以工作了!

public static $tenancyMiddleware = 'Stancl\Tenancy\Middleware\InitializeTenancyByDomainOrSubdomain';
© www.soinside.com 2019 - 2024. All rights reserved.