使用 laravel 和 nuxt js 的多租户显示公司徽标时出现问题

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

我的项目中安装了 Laravel 租户,因此我的图像已正确上传并存储在特定租户文件夹的存储文件夹中,然后是图像名称!但我怎样才能显示这个呢?对于存储,如果我使用 storage_path 它会采用整个路径

file:///C:/wamp64/www/toplimo/toplimo_server/storage/tenanta21e21ae-e338-4355-9c20-686335d9dea6/logos/ehZImdggil6PTsuUBVQAQGNkCthdFFBUCYI4o7GT.jpg !!
所以为了存储我只是存储徽标/图像名称!就是这样,但如果我在访问时使用 storage_path 那么它会给出这个并说不允许加载本地资源!!

$path = $request->file('logo')->store('logo');
    
            // Save the file name to the database
            $company->logo = $path;
            $company->save();

这就是我保存数据的方式,但如果我用它来获取个人资料详细信息和徽标---------

$profile_data->company_logo = storage_path($company_details->logo);

它给出了上面的链接文件:///C:/wamp64/www/toplimo/toplimo_server/storage/tenanta21e21ae-e338-4355-9c20-686335d9dea6/logos/ehZImdggil6PTsuUBVQAQGNkCthdFFBUCYI4o7GT.jpg,我无法使用


$profile_data->company_logo = Storage::disk('logos')->path($company_details->logo); 

帮我展示一下!!我想在这里展示

if (this.profileData && this.profileData.company_logo) {
              // Assuming your backend serves the logos from a specific URL, like '/logos/'
              // You may need to adjust this URL based on your server setup
              this.form.company.logo =  'http://domain1.localhost:8000/logos/' + this.profileData.company_logo.split('/').pop();
              console.log(this.form.company.logo);
            } 

this.form.company.logo 应显示正确的值,并且我正在 domain1.localhost:8000 上运行服务器

我不想公开提供我的图像/徽标,因此它应该仅从租户中挑选

laravel vue.js nuxt.js multi-tenant tenancyforlaravel
1个回答
0
投票

为了存储它,我使用了-

        $File = $request->file('logo');
        $path = $request->file('logo')->store('logos');

        // Save the file name to the database
        $company->logo = $path;
        $company->save();

        $stored = Storage::disk('public')->put("logos", $File);
        $url = tenant_asset($stored);
        return response()->json(['success' =>$url], 200);   

它给出的答案为“成功”:“http://domain1.localhost:8000/tenancy/assets/logos/RoNnhVVmuQqgLM2czVncOjgb1EYizX7Q1sfoPrUB.png”,以便显示它,

       console.log(response.success);
      // Remove extra slashes from the response URL
      let cleanedUrl = response.success.replace(/([^:]\/)\/+/g, "$1");

      // Set the cleaned URL to the form's company logo property
      this.form.company.logo = cleanedUrl;
      this.$toast.success("Company Logo Updated Successfully");
      console.log(this.form.company.logo);
© www.soinside.com 2019 - 2024. All rights reserved.