承接 finnwiel/shazzoo-media 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

finnwiel/shazzoo-media

Composer 安装命令:

composer require finnwiel/shazzoo-media

包简介

A media library for Laravel

README 文档

README

License Packagist Version Laravel Filament PHP

A Laravel + Filament plugin that extends Filament Curator with custom media conversion logic and a customized media model.

Installation

⚠️ Important: Before installing, make sure the GD extension is enabled in your php.ini. Without it, image conversions will fail and no thumbnails will be generated.

You can install the package via composer then run the installation command:

composer require finnwiel/shazzoo-media

If you installed Curator before Shazzoo Media, you’ll need to remove Curator’s media table migration manually before running the install command.

php artisan shazzoo_media:install

Note: This plugin will install Curator for you, but you still need to set up your Filament panel theme.

Import Curator's stylesheet in your Filament panel theme CSS file.

@import '../../../../vendor/awcodes/filament-curator/resources/css/plugin.css';

Add Curator and Shazzoo Media views to your theme sources.

@source '../../../../vendor/awcodes/filament-curator/resources/views/**/*.blade.php';
@source '../../../../vendor/finnwiel/shazzoo-media/resources/views/**/*.blade.php';

Usage

Global settings

The plugins settings can be managed through the config file

php artisan vendor:publish --tag=shazzoo_media-config

Note: This plugin will also change some of curators settings, you can still manage curators setting but they may not work with Shazzoo Media

To publish the plugins Model run:

php artisan vendor:publish --tag=shazzoo-media-model

Important: When publishing the model make sure to also change the model in the config.

Filament Panels

If you are using Filament Panels you will need to add the Plugin to your Panel's configuration. This will register the plugin's resources with the Panel. All methods are optional, and will be read from the config file if not provided.

public function panel(Panel $panel): Panel
{
    return $panel
        ->viteTheme('resources/css/filament/admin/theme.css')
        ->plugins([
                \Awcodes\Curator\CuratorPlugin::make()
                    ->label('Media')
                    ->registerNavigation(true)
                    ->showBadge(true)
            ])
}

Picker field

Shazzoo Media adds a conversions method to the picker field, this method accepts an array. The conversions will subsequently be set in the database for each array item. Shazzoo Media will also create the conversion image.

The picker also has a fileType method, this accepts the following strings: 'image', 'icon', 'document'.

Commands Tags
image jpeg png, webp, gif
icon svg
document pdf docx
ShazzooMediaPicker::make('featured_image_id')
                    ->conversions(['thumbnail'])
                    ->fileType(), // 'image', 'icon', 'document'

To generate actually set the conversions in the database you need to add a trait to the create and edit classes of your resource.

use FinnWiel\ShazzooMedia\Traits\HandlesConversions;

class CreatePost extends CreateRecord
{
    use HandlesConversions;

    protected static string $resource = PostResource::class;
}

Conversions

Conversions are set in config/shazzoo_media.php in the conversions array. To add or remove conversions change the array with the same structure.

'conversions' => [
    'profile' => ['width' => 80, 'height' => 80],
    'thumbnail' => ['width' => 200, 'height' => 200],
    'medium' => ['width' => 400, 'height' => 400],
    'large' => ['width' => 600, 'height' => 600],
],

So adding a new conversion called small would look like this:

'conversions' => [
    'profile' => ['width' => 80, 'height' => 80, 'fit' => 'crop'],
    'thumbnail' => ['width' => 200, 'height' => 200],
    'medium' => ['width' => 400, 'height' => 400],
    'large' => ['width' => 600, 'height' => 600],
    'small' => ['width' => 100, 'height' => 100],
],

As you can see the existing conversions can also be edited, this can even be done when some conversions have already been made. Just be sure to run the php artisan media:conversions:regenerate command. This will regenerate the conversions to the new sizes.

Showing images

To show images in your frontend using the ShazzooMedia model, you can leverage the built-in dynamic URL accessors for media conversions.

For each image conversion defined in your config (shazzoo_media.conversions), a dynamic property is available on your media model:

$image->thumbnail_url  // returns URL for the 'thumbnail' conversion
$image->web_url        // returns URL for the 'web' conversion

If the conversion file exists, it returns the converted image URL. If not, it gracefully falls back to the original image URL.

Example in blade:

<img src="{{ $media->thumbnail_url }}" alt="Thumbnail">

Defining relationships

You are responsible for defining the relationship between your Eloquent models and the media records.

One-to-One Example:

For a model that has a single media item, like a Post with a featured image:

// In your Post.php model
use FinnWiel\ShazzooMedia\Models\ShazzooMedia;

public function featuredImage()
{
    return $this->belongsTo(ShazzooMedia::class, 'media_id');
}

Usage:

<img src="{{ $post->featuredImage?->thumbnail_url }}" alt="Featured image">
One-to-Many Example:

For a model that has multiple images, like a Product with a gallery:

// In your Product.php model
use FinnWiel\ShazzooMedia\Models\ShazzooMedia;

public function gallery()
{
    return $this->hasMany(ShazzooMedia::class, 'product_id');
}

Usage:

@foreach($product->gallery as $image)
    <img src="{{ $image->web_url }}" alt="Gallery image">
@endforeach

Artisan commands

The Shazzoo Media plugin uses some artisan commands.

Commands Tags Uses
media:clear - Clears your image files from the storage folder.
media:clear-conversions - Clears your image conversion files from the storage folder.
media:conversions:clear-db id Clears conversion(s) in the database.
media:conversions:set-db id append Sets conversion(s) in the databse.
media:conversions:generate id all only Generates the conversions for the images.
media:conversions:regenerate id only Regenerates the conversions for the images.
media:conversions:list - Lists out all image conversions

Policies & Tenancy

Policies

The Shazzoo Media library doesn't use a policy by default but lets you publish a policy template.

php artisan vendor:publish --tag=shazzoo-media-policy

This will publish a policy file to App/Policies/MediaPolicy.php the policy should be registered automatically by the plugin. The published file will be a blank policy, you will need to add your own rules. Also make sure that media_policies is set to true in the config/shazzoo_media.php.

Tenancy

This package does not implement tenancy or user-based access control out of the box.

If your application requires scoping media by tenant, team, or user, you are responsible for applying your own global scope to the ShazzooMedia model. This can be done by publishing the model and implementing it there, or you can add the global scope in the AppServiceProvider.php's boot function.

finnwiel/shazzoo-media 适用场景与选型建议

finnwiel/shazzoo-media 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 195 次下载、GitHub Stars 达 1, 最近一次更新时间为 2025 年 05 月 06 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 finnwiel/shazzoo-media 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 finnwiel/shazzoo-media 我们能提供哪些服务?
定制开发 / 二次开发

基于 finnwiel/shazzoo-media 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 195
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 3
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-05-06