首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >声明MediaLibrary/CustomPathGenerator.php文件时出错

声明MediaLibrary/CustomPathGenerator.php文件时出错
EN

Stack Overflow用户
提问于 2022-02-16 16:18:16
回答 1查看 394关注 0票数 1

在laravel 9中,空间/laravel-medialibrary 10 I类型为上传的文件创建自定义路径,查看docs:https://spatie.be/docs/laravel-medialibrary/v9/advanced-usage/using-a-custom-directory-structure,但生成https://spatie.be/docs/laravel-medialibrary/v9/advanced-usage/using-a-custom-directory-structure文件:

代码语言:javascript
复制
<?php

namespace App\Services\MediaLibrary;
//namespace App\MediaLibrary;

use Spatie\MediaLibrary\MediaCollections\Models\Media;
use Spatie\MediaLibrary\PathGenerator\PathGenerator;

//class CustomPathGenerator implements BasePathGenerator
class CustomPathGenerator implements PathGenerator
{
    /*
     * Get the path for the given media, relative to the root storage path.
     */
    public function getPath(Media $media): string
    {
        return md5($media->id .  config('app.key')) .'/';
    }

    /*
     * Get the path for conversions of the given media, relative to the root storage path.
     */
    public function getPathForConversions(Media $media): string
    {
        return md5($media->id .  config('app.key')) .'/conversions/';

    }

    /*
     * Get the path for responsive images of the given media, relative to the root storage path.
     */
    public function getPathForResponsiveImages(Media $media): string {
        return md5($media->id .  config('app.key')) .'/responsive-images/';

    }
}

我有错误:

代码语言:javascript
复制
[2022-02-16 17:52:44] local.ERROR: Interface "App\Services\MediaLibrary\BasePathGenerator" not found {"userId":1,"exception":"[object] (Error(code: 0): Interface \"App\\Services\\MediaLibrary\\BasePathGenerator\" not found at /mnt/_work_sdb8/wwwroot/lar/hostels4j/app/Services/MediaLibrary/CustomPathGenerator.php:8)

看起来我的文件头是无效的。

哪种方法是解决问题的有效方法?

提前感谢!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-02-27 13:58:15

您错误地定义了BasePathGenerator,请使用以下方法

代码语言:javascript
复制
<?php

namespace App\Services\MediaLibrary;

use Spatie\MediaLibrary\MediaCollections\Models\Media;
use Spatie\MediaLibrary\Support\PathGenerator\PathGenerator as BasePathGenerator;

class CustomPathGenerator implements BasePathGenerator {
        /*
     * Get the path for the given media, relative to the root storage path.
     */
    public function getPath(Media $media): string {
        return '';
    }

    /*
     * Get the path for conversions of the given media, relative to the root storage path.
     */
    public function getPathForConversions(Media $media): string {
        return '';
    }

    /*
     * Get the path for responsive images of the given media, relative to the root storage path.
     */
    public function getPathForResponsiveImages(Media $media): string {
        return '';
    }
}

这应该能解决你的问题。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71145458

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档