承接 mortezaa97/catalogs 相关项目开发

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

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

mortezaa97/catalogs

Composer 安装命令:

composer require mortezaa97/catalogs

包简介

README 文档

README

A Laravel package for managing catalogs with polymorphic relationships, allowing you to categorize and organize any model in your application.

Features

  • 📁 Flexible Catalog Management - Create and manage catalogs with hierarchical organization
  • 🔗 Polymorphic Relationships - Attach catalogs to any model in your application
  • 🎨 SEO Friendly - Built-in support for meta titles, descriptions, and keywords
  • 📸 Image Support - Upload and manage catalog images
  • 🔢 Custom Ordering - Control the display order of catalogs and related models
  • 👥 User Tracking - Track who created and updated each catalog
  • 🗑️ Soft Deletes - Safely delete catalogs with the ability to restore
  • 🚦 Status Management - Enable/disable catalogs with status control
  • 🔐 Policy Based Authorization - Built-in policies for catalog management
  • 🌐 API Ready - RESTful API routes included

Requirements

  • PHP ^8.2
  • Laravel ^8.12|^9.0|^10.0|^11.0|^12.0

Installation

1. Install via Composer

composer require mortezaa97/catalogs

2. Publish Configuration (Optional)

php artisan vendor:publish --provider="Mortezaa97\Catalogs\CatalogsServiceProvider" --tag="config"

3. Publish Migrations (Optional)

If you want to customize the migrations:

php artisan vendor:publish --provider="Mortezaa97\Catalogs\CatalogsServiceProvider" --tag="migrations"

4. Run Migrations

php artisan migrate

Database Structure

Catalogs Table

The main catalogs table includes:

  • id - Primary key
  • title - Catalog title
  • slug - URL-friendly slug
  • desc - Long text description
  • image - Image path
  • page_title - Custom page title
  • meta_title - SEO meta title
  • meta_desc - SEO meta description
  • meta_keywords - JSON array of keywords
  • order - Display order (default: 0)
  • status - Active/Inactive status
  • created_by - Foreign key to users table
  • updated_by - Foreign key to users table
  • deleted_at - Soft delete timestamp
  • created_at / updated_at - Timestamps

Model Has Catalogs Table

Polymorphic pivot table for attaching catalogs to models:

  • id - Primary key
  • catalog_id - Foreign key to catalogs table
  • model_id - Polymorphic ID
  • model_type - Polymorphic type
  • created_at / updated_at - Timestamps

Unique constraint on [catalog_id, model_id, model_type]

Usage

Basic Usage

Creating a Catalog

use Mortezaa97\Catalogs\Models\Catalog;

$catalog = Catalog::create([
    'title' => 'Electronics',
    'slug' => 'electronics',
    'desc' => 'All electronic products',
    'image' => 'path/to/image.jpg',
    'page_title' => 'Electronics | MyStore',
    'meta_title' => 'Buy Electronics Online',
    'meta_desc' => 'Shop the latest electronics',
    'meta_keywords' => ['electronics', 'gadgets', 'tech'],
    'order' => 1,
    'status' => 1,
    'created_by' => auth()->id(),
]);

Retrieving Catalogs

// Get all catalogs (ordered by created_at desc)
$catalogs = Catalog::all();

// Get active catalogs
$activeCatalogs = Catalog::where('status', 1)->get();

// Get catalog by slug
$catalog = Catalog::where('slug', 'electronics')->first();

Working with Polymorphic Relationships

Attach a Catalog to a Model

use Mortezaa97\Catalogs\Models\ModelHasCatalog;

// Attach a product to a catalog
ModelHasCatalog::create([
    'catalog_id' => $catalog->id,
    'model_id' => $product->id,
    'model_type' => get_class($product),
]);

Using in Your Models

Add the relationship to your model:

use Illuminate\Database\Eloquent\Model;
use Mortezaa97\Catalogs\Models\Catalog;

class Product extends Model
{
    public function catalogs()
    {
        return $this->morphToMany(
            Catalog::class,
            'model',
            'model_has_catalogs'
        )->withTimestamps();
    }
}

Then use it:

// Get all catalogs for a product
$catalogs = $product->catalogs;

// Get all products in a catalog
$products = $catalog->products;

// Attach a product to a catalog
$product->catalogs()->attach($catalog->id);

// Detach a product from a catalog
$product->catalogs()->detach($catalog->id);

// Sync catalogs for a product
$product->catalogs()->sync([1, 2, 3]);

Using the Facade

use Catalogs;

// Use the facade for custom functionality
// (Extend the main Catalogs class as needed)

API Routes

The package includes API route scaffolding. You can define your routes in:

packages/mortezaa97/catalogs/routes/api.php

Authorization

The package includes built-in policies:

  • CatalogPolicy - For catalog CRUD operations
  • ModelHasCatalogPolicy - For managing catalog relationships

Gates

The policies are automatically registered with Laravel's Gate system:

// Check if user can view catalog
if (Gate::allows('view', $catalog)) {
    // User can view
}

// Check if user can create catalog
if (Gate::allows('create', Catalog::class)) {
    // User can create
}

Configuration

After publishing the config file, you can customize settings in config/catalogs.php:

return [
    // Add your custom configuration here
];

Models

Catalog Model

Main model for catalogs with:

  • Soft deletes support
  • Automatic ordering by created_at
  • Relationships to User (created_by, updated_by)
  • Polymorphic relationship to products (or any model)

ModelHasCatalog Model

Pivot model for polymorphic relationships with:

  • Automatic ordering by created_at
  • Relationship to Catalog

Testing

Run the test suite:

composer test

Generate coverage report:

composer test-coverage

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.

Changelog

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

Support

For support, please open an issue on GitHub or contact mortezajafari76@gmail.com.

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

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

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

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

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