PHPackages                             mortezaa97/catalogs - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. mortezaa97/catalogs

ActiveLibrary

mortezaa97/catalogs
===================

v1.0.6(6mo ago)00MITPHPPHP ^8.2CI passing

Since Oct 25Pushed 6mo agoCompare

[ Source](https://github.com/mortezaa97/catalog)[ Packagist](https://packagist.org/packages/mortezaa97/catalogs)[ Docs](https://github.com/mortezaa97/catalogs)[ RSS](/packages/mortezaa97-catalogs/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (7)Dependencies (4)Versions (8)Used By (0)

Catalogs Package
================

[](#catalogs-package)

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

Features
--------

[](#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
------------

[](#requirements)

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

Installation
------------

[](#installation)

### 1. Install via Composer

[](#1-install-via-composer)

```
composer require mortezaa97/catalogs

```

### 2. Publish Configuration (Optional)

[](#2-publish-configuration-optional)

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

```

### 3. Publish Migrations (Optional)

[](#3-publish-migrations-optional)

If you want to customize the migrations:

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

```

### 4. Run Migrations

[](#4-run-migrations)

```
php artisan migrate

```

Database Structure
------------------

[](#database-structure)

### Catalogs Table

[](#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

[](#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
-----

[](#usage)

### Basic Usage

[](#basic-usage)

#### Creating a Catalog

[](#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

[](#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

[](#working-with-polymorphic-relationships)

#### Attach a Catalog to a Model

[](#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

[](#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

[](#using-the-facade)

```
use Catalogs;

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

```

API Routes
----------

[](#api-routes)

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

```
packages/mortezaa97/catalogs/routes/api.php

```

Authorization
-------------

[](#authorization)

The package includes built-in policies:

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

### Gates

[](#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
-------------

[](#configuration)

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

```
return [
    // Add your custom configuration here
];

```

Models
------

[](#models)

### Catalog Model

[](#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

[](#modelhascatalog-model)

Pivot model for polymorphic relationships with:

- Automatic ordering by created\_at
- Relationship to Catalog

Testing
-------

[](#testing)

Run the test suite:

```
composer test

```

Generate coverage report:

```
composer test-coverage

```

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Security
--------

[](#security)

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

Credits
-------

[](#credits)

- [Morteza Jafari](https://github.com/mortezaa97)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Support
-------

[](#support)

For support, please open an issue on GitHub or contact .

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance68

Regular maintenance activity

Popularity0

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity52

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~3 days

Total

7

Last Release

189d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/eb4593fe9950cffcc4459b71bbd4aa5f378c28c8e546dffb8981898f31ed8b26?d=identicon)[mortezajafari76](/maintainers/mortezajafari76)

---

Top Contributors

[![mortezaa97](https://avatars.githubusercontent.com/u/57325086?v=4)](https://github.com/mortezaa97 "mortezaa97 (7 commits)")

---

Tags

mortezaa97catalogs

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/mortezaa97-catalogs/health.svg)

```
[![Health](https://phpackages.com/badges/mortezaa97-catalogs/health.svg)](https://phpackages.com/packages/mortezaa97-catalogs)
```

###  Alternatives

[larastan/larastan

Larastan - Discover bugs in your code without running it. A phpstan/phpstan extension for Laravel

6.4k43.5M5.2k](/packages/larastan-larastan)[laravel/passport

Laravel Passport provides OAuth2 server support to Laravel.

3.4k85.0M532](/packages/laravel-passport)[illuminate/database

The Illuminate Database package.

2.8k52.4M9.4k](/packages/illuminate-database)[laravel/mcp

Rapidly build MCP servers for your Laravel applications.

74310.9M66](/packages/laravel-mcp)[illuminate/view

The Illuminate View package.

13044.9M1.7k](/packages/illuminate-view)[dyrynda/laravel-model-uuid

This package allows you to easily work with UUIDs in your Laravel models.

4802.8M8](/packages/dyrynda-laravel-model-uuid)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
