mortezaa97/brands 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

mortezaa97/brands

Composer 安装命令:

composer require mortezaa97/brands

包简介

README 文档

README

Latest Version on Packagist Total Downloads

A Laravel package for managing product brands with full API support, authorization policies, and Filament integration.

Features

  • ✅ Complete CRUD operations for brands
  • ✅ RESTful API endpoints with resource transformers
  • ✅ Authorization policies for granular access control
  • ✅ Soft deletes support
  • ✅ Category relationships
  • ✅ SEO-friendly with meta fields
  • ✅ Slug-based routing
  • ✅ User tracking (created by/updated by)
  • ✅ Filament plugin ready
  • ✅ API Resources for simple and detailed responses

Installation

You can install the package via composer:

composer require mortezaa97/brands

Service Provider Registration

The package will automatically register its service provider. If you need to manually register it, add the following to your config/app.php:

'providers' => [
    // ...
    Mortezaa97\Brands\BrandsServiceProvider::class,
],

Publish Assets

Publish the configuration file:

php artisan vendor:publish --provider="Mortezaa97\Brands\BrandsServiceProvider" --tag="config"

Publish migrations (optional, migrations are loaded automatically):

php artisan vendor:publish --provider="Mortezaa97\Brands\BrandsServiceProvider" --tag="migrations"

Run Migrations

Run the migrations to create the brands table:

php artisan migrate

Database Schema

The brands table includes the following fields:

Field Type Description
id bigint Primary key
name string Brand name
slug string URL-friendly identifier
logo string (nullable) Logo file path
status smallint Brand status (active/inactive)
category_id foreignId (nullable) Related category
desc longText (nullable) Brand description
meta_title string (nullable) SEO meta title
meta_desc longText (nullable) SEO meta description
meta_keywords string (nullable) SEO keywords
page_title string (nullable) Page display title
color string (nullable) Brand color theme
created_by foreignId User who created the brand
updated_by foreignId (nullable) User who last updated the brand
deleted_at timestamp (nullable) Soft delete timestamp
created_at timestamp Creation timestamp
updated_at timestamp Last update timestamp

Configuration

The configuration file config/brands.php allows you to customize:

return [
    'table_name' => 'brands', // Customize table name if needed
];

Usage

API Endpoints

The package automatically registers the following API routes:

Get All Brands

GET /api/brands

Returns a collection of brands with simple resource transformation.

Response:

[
    {
        "name": "Nike",
        "slug": "nike",
        "logo": "https://example.com/storage/logos/nike.png",
        "color": "#000000"
    }
]

Get Single Brand

GET /api/brands/{slug}

Returns a detailed brand resource including category relationship.

Response:

{
    "name": "Nike",
    "slug": "nike",
    "logo": "https://example.com/storage/logos/nike.png",
    "desc": "Nike is a leading sportswear brand...",
    "meta_title": "Nike - Premium Sportswear",
    "meta_desc": "Discover Nike products...",
    "meta_keywords": "nike, sportswear, shoes",
    "page_title": "Nike Official Store",
    "color": "#000000",
    "category": {
        "id": 1,
        "name": "Sportswear",
        "slug": "sportswear"
    }
}

Using in Your Code

Create a Brand

use Mortezaa97\Brands\Models\Brand;

$brand = Brand::create([
    'name' => 'Adidas',
    'slug' => 'adidas',
    'logo' => 'path/to/logo.png',
    'status' => Status::ACTIVE,
    'category_id' => 1,
    'desc' => 'Premium sportswear brand',
    'meta_title' => 'Adidas Official',
    'color' => '#000000',
    'created_by' => auth()->id(),
]);

Query Brands

// Get all active brands
$brands = Brand::all();

// Get brand by slug
$brand = Brand::where('slug', 'nike')->first();

// Get brands with category
$brands = Brand::with('category')->get();

// Get brands created by specific user
$brands = Brand::whereHas('createdBy', function($query) {
    $query->where('id', 1);
})->get();

Update a Brand

$brand = Brand::find(1);
$brand->update([
    'name' => 'Updated Brand Name',
    'updated_by' => auth()->id(),
]);

Delete a Brand (Soft Delete)

$brand = Brand::find(1);
$brand->delete(); // Soft delete

// Restore
$brand->restore();

// Force delete
$brand->forceDelete();

Relationships

The Brand model includes the following relationships:

Category

$brand = Brand::with('category')->first();
$categoryName = $brand->category->name;

Created By User

$brand = Brand::with('createdBy')->first();
$creatorName = $brand->createdBy->name;

Updated By User

$brand = Brand::with('updatedBy')->first();
if ($brand->updatedBy) {
    $updaterName = $brand->updatedBy->name;
}

Authorization

The package includes a BrandPolicy for authorization. The following gates are available:

  • viewAny - View list of brands
  • view - View single brand
  • create - Create new brand
  • update - Update existing brand
  • delete - Delete brand
  • restore - Restore soft-deleted brand
  • forceDelete - Permanently delete brand

Example usage in your controllers:

use Illuminate\Support\Facades\Gate;

// Check if user can view brands
if (Gate::allows('viewAny', Brand::class)) {
    // User can view brands
}

// Authorize specific brand action
Gate::authorize('update', $brand);

API Resources

The package provides two resource transformers:

BrandResource

Full details including relationships and SEO fields.

use Mortezaa97\Brands\Http\Resources\BrandResource;

return new BrandResource($brand);

BrandSimpleResource

Simplified response for list views.

use Mortezaa97\Brands\Http\Resources\BrandSimpleResource;

return BrandSimpleResource::collection($brands);

Filament Integration

To integrate with Filament, register the plugin in your panel provider:

use Mortezaa97\Brands\BrandsPlugin;

public function panel(Panel $panel): Panel
{
    return $panel
        ->plugins([
            BrandsPlugin::make(),
        ]);
}

Facade

You can use the Brands facade for convenient access:

use Mortezaa97\Brands\BrandsFacade as Brands;

// Use the facade
Brands::someMethod();

Global Scope

The Brand model includes a global scope that orders all queries by created_at in descending order (newest first).

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email mortezajafari76@gmail.com instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

mortezaa97/brands 适用场景与选型建议

mortezaa97/brands 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 0 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 10 月 24 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 mortezaa97/brands 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-10-24