承接 souravmsh/laravel-widget 相关项目开发

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

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

souravmsh/laravel-widget

Composer 安装命令:

composer require souravmsh/laravel-widget

包简介

A Laravel package for building and bundling reusable UI widgets as Blade components.

README 文档

README

A Laravel package for building and bundling reusable UI widgets as Blade components.

Overview

laravel-widget is a Laravel package designed to manage a collection of UI widgets that can be easily embedded into any Laravel Blade view. The package simplifies widget integration while maintaining a clean, modern interface.

The package currently includes two widgets:

  • Font Hunter: A utility to download Google Fonts and their CSS files via a simple form.
  • Avatar Widget: A component to display an avatar image or generate a fallback avatar based on text initials.

Features

  • Widget Bundle Ready: Designed to host multiple widgets under one package.
  • Reusable Blade Components: Easily embed widgets using Blade components.
  • Customizable Configurations: Control storage paths, file names, and other settings for Font Hunter, and avatar appearance for the Avatar Widget.

Requirements

  • PHP 8.0 or higher
  • Laravel 9.x or 10.x
  • Writable storage directory (storage/app/public)
  • GD PHP extension (for Avatar Widget image generation)

Installation

  1. Install via Composer

    If published to a repository:

    composer require souravmsh/laravel-widget

    If developing locally:

    // Add to composer.json
    "repositories": [
        {
            "type": "path",
            "url": "packages/souravmsh/laravel-widget"
        }
    ]
    composer require souravmsh/laravel-widget:dev-main
  2. Publish Configuration & Views

    php artisan vendor:publish --tag=config
    php artisan vendor:publish --tag=views
  3. Set Storage Permissions

    chmod -R 775 storage
    php artisan storage:link

Usage

1. Font Hunter Widget

Font Hunter Widget is a Laravel package that provides a reusable, interactive Blade component for downloading Google Fonts and their associated CSS files. With a modern, Tailwind CSS-powered interface, users can input a Google Fonts CSS URL, fetch the font files, generate a custom CSS, and download everything as a convenient zip archive.

Font Hunter Widget Preview

Usage:

<x-laravel-widget::font-hunter />

or

<x-laravel-widget::font-hunter 
    title="Font Hunter" 
    description="Download any font by entering the URL of the font file."
/>

Workflow:

  1. Enter a valid Google Fonts CSS URL (e.g., https://fonts.googleapis.com/css?family=Lato:300,400,700).
  2. Click Generate to fetch the fonts and CSS.
  3. A Download button appears to download a zip archive containing the fonts and a generated CSS file.

2. Avatar Widget

Avatar Widget is a reusable Blade component that displays an avatar image from a provided URL or generates a fallback avatar using text initials. If the provided image URL is invalid or not provided, the widget generates an avatar with initials derived from the alt text or the src filename, displayed on a random background color with contrasting text.

Usage:

<x-laravel-widget::avatar
    src="http://0.0.0.0:8804/assets/images/icon/logo.png"
    alt="Company Logo"
/>

or

<x-laravel-widget::avatar
    src="http://0.0.0.0:8804/assets/images/users/photo.png"
    alt="Profile Photo"
    width="64"
    height="64"
    class="text-class"
    id="myImage"
    data-tg-title='Simple avatar'
/>

Features:

  • Displays an image from the src URL if valid.
  • Generates a fallback avatar with initials if src is invalid or missing:
    • Uses alt text for initials (e.g., "Font 2" → "F2").
    • If alt is missing, extracts initials from the src filename (e.g., "no.png" → "N").
    • If both are missing, uses default alt ("Avatar" → "A").
  • Supports custom width, height, class, id, and additional HTML attributes via attributes.
  • Percentage-based height (e.g., height="48%") is applied as CSS style.
  • Width and height are only applied if provided for valid images; fallback avatars use provided or default dimensions (48x48).

Behavior:

  • If the src image loads successfully, it uses the provided width, height, and custom attributes, with natural image dimensions if width or height are not specified.
  • If the src fails (e.g., 404), a JavaScript onerror handler swaps to a generated avatar with default or provided dimensions, preserving all custom attributes.

Configuration

Customize the package settings in config/laravel-widget.php:

return [
    'middleware' => ['web'], // Middleware for the route
    'url_prefix' => 'laravel-widget', // URL prefix for the route

    // Font Hunter
    'font_hunter' => [
        'dir'        => 'laravel-widget/font-hunter', // Base directory for storing files
        'fonts_dir'  => 'fonts', // Subdirectory for font files
        'css_dir'    => 'css', // Subdirectory for CSS files
        'file_name'  => 'fonts.css', // Name of the CSS file
    ],

    // Avatar Widget
    'avatar' => [
        'src'     => null,
        'alt'     => 'Avatar',
        'width'   => 48,
        'height'  => 48,
        'id'      => null,
        'classes' => null,
        'style'   => null,
        'attributes' => null,
    ]
];

You can adjust:

  • Font Hunter: Base storage path, subdirectories for fonts and CSS, and default CSS filename.
  • Avatar Widget: Default values for src, alt, width, height, id, classes, style, and attributes.

Customization

  • Styling:
    • For Font Hunter, edit resources/views/vendor/laravel-widget/components/font-hunter.blade.php.
    • For Avatar Widget, edit resources/views/vendor/laravel-widget/avatar/index.blade.php.
  • Form Handling: Optionally convert the Font Hunter form to AJAX-based by adding custom JavaScript.
  • Additional Widgets: Create new Blade components within the package to add more widgets.
  • Avatar Appearance: Modify the AvatarService class to customize fallback avatar generation (e.g., colors, fonts).

Notes

  • Files for Font Hunter are stored at storage/app/public/laravel-widget/. Ensure this directory is writable.
  • The Font Hunter widget uses a minimal POST route /laravel-widget/process to handle form submissions.
  • The Avatar Widget requires the GD PHP extension for generating fallback avatars.
  • Fully compatible with Laravel 9.x and 10.x.

License

This package is open-source software licensed under the MIT license.

Support

For issues or feature requests, open an issue on the GitHub repository.

souravmsh/laravel-widget 适用场景与选型建议

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

它主要适用于以下技术方向: 「laravel」 「souravmsh」 「laravel-widget」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

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

围绕 souravmsh/laravel-widget 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

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