sadeem-tech/category

adds category stuff to a project


Keywords
api, category, migration, model, laravel
License
MIT

Documentation

Sadeem Tech / Category

sadeem-folder

This is a postgres database model, migration and controller for a common category table used in multiple projects

install using:

composer require sadeem-tech/category

Publish migrations and config:

php artisan vendor:publish --provider="SadeemTech\Category\CategoryServiceProvider"

Usage

the category model

column type description
id uuid identifier
name string category name
is_disabled boolean status
parent_id uuid null on top level categories, has value of a higher level category on sub levels
model_name string model to associate category with (only for top level categories), null on lower level categories

example

id name is_disabled parent_id model_name
1 news false null article
2 events false null article
3 breaking false 1 null
4 company false 1 null
5 solar_eclipse false 2 null
6 full_moon false 2 null

api resource routes available:

index: categories model can use the searchAndSort(request) function to handle the request using the following params:

param value description
q string use similarity string search on name column
sort asc / desc order of sort
sort_by column helper function confirms the column by schema

Trait

use HasCategories; inside a class to define a hasMany relation using categories()

Postgres required extensions

Name command Description
UUID CREATE EXTENSION "uuid-ossp"; uuid support for primary keys
Trigram CREATE EXTENSION pg_trgm; Levenshtein (string similarity) functions

Configuration

inside your app root config/sadeem.php

variable value description
category_table_name categories migration table name
category_table_timestamps true enable or disable timestamps