【问题标题】:how to get image from storage folder using tenancy laravel如何使用租赁 laravel 从存储文件夹中获取图像
【发布时间】:2019-04-03 17:11:09
【问题描述】:

请回答,如何使用租赁 laravel 从存储文件夹中获取图像。

【问题讨论】:

  • 我们需要更多解释。
  • 如何创建 laravel storage:link 自定义路径?我想点project/public/storage >> project/storage/app/tenancy/tenants

标签: laravel multi-tenant laravel-5.6


【解决方案1】:

我在这里遇到了同样的问题,这是我使用 Hyn 5.4 的解决方案,您可以像这样检索当前租户:

https://laravel-tenancy.com/docs/hyn/5.4/identification#retrieve-current-tenant

 // Get current Website (Tenant)
 $website   = \Hyn\Tenancy\Facades\TenancyFacade::website();

 // prefered option
 $website   = app(\Hyn\Tenancy\Environment::class)->tenant();

 // alternative (outdated) 
 $website   = app(\Hyn\Tenancy\Environment::class)->website();

 $websiteId = $website->id;

 // Get current Hostname
 $hostname  = app(\Hyn\Tenancy\Environment::class)->hostname();

 // Get FQDN (Fully-Qualified Domain Name) by current hostname
 $fqdn      = $hostname->fqdn;

您可以通过创建将链接到 租户媒体
https://laravel-tenancy.com/docs/hyn/5.4/structure#media

Route::get('/media/{path}', '\Hyn\Tenancy\Controllers\MediaController')
->where('path', '.+')
->name('tenant.media');

【讨论】:

  • 调用/注入自定义模型到控制器/视图的最佳方式是什么?
【解决方案2】:

如果您想创建自定义存储磁盘,您可以在config/filesystems.php 中添加,在disk 下输入此代码。

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

所以你可以使用Storage::disk('tenancy')访问它

例如

Storage::disk('tenancy')->get('tenants/64121.../images');

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-11-10
    • 2021-09-25
    • 2016-09-01
    • 1970-01-01
    • 1970-01-01
    • 2019-10-16
    • 2020-06-22
    • 1970-01-01
    相关资源
    最近更新 更多