webpress / category-manager
This package's canonical repository appears to be gone and the package has been frozen as a result.
Installs: 2 858
Dependents: 4
Suggesters: 0
Security: 0
Stars: 1
Watchers: 2
Forks: 7
Open Issues: 0
Requires
- cviebrock/eloquent-sluggable: 7.0.1
- doctrine/dbal: v2.12.1
- webpress/core: ^3.1
Requires (Dev)
- orchestra/testbench: 5.0.0
- dev-master
- 3.1.87
- 3.1.86
- 3.1.85
- 3.1.83
- 3.1.82
- 3.1.81
- 3.1.80
- 3.1.79
- 3.1.78
- 3.1.77
- 3.1.76
- 3.1.74
- 3.1.73
- 3.1.72
- 3.1.71
- 3.1.70
- 3.1.69
- 3.1.68
- 3.1.67
- 3.1.66
- 3.1.65
- 3.1.64
- 3.1.63
- 3.1.61
- 3.1.60
- 3.1.59
- 3.1.58
- 3.1.57
- 3.1.56
- 3.1.54
- 3.1.53
- 3.1.52
- 3.1.51
- 3.1.50
- 3.1.49
- 3.1.48
- 3.1.47
- 3.1.46
- 3.1.45
- 3.1.44
- 3.1.43
- 3.1.42
- 3.1.41
- 3.1.40
- 3.1.39
- 3.1.38
- 3.1.37
- 3.1.36
- 3.1.35
- 3.1.34
- 3.1.33
- 3.1.32
- 3.1.31
- 3.1.30
- 3.1.29
- 3.1.28
- 3.1.27
- 3.1.26
- 3.1.25
- 3.1.24
- 3.1.23
- 3.1.22
- 3.1.20
- 3.1.19
- 3.1.18
- 3.1.17
- 3.1.15
- 3.1.14
- 3.1.13
- 3.1.12
- 3.1.11
- 3.1.10
- 3.1.9
- 3.1.8
- 3.1.7
- 3.1.6
- 3.1.5
- 3.1.3
- 3.1.2
- 3.1.1
- 3.1.0
- 3.0.34
- 3.0.33
- 3.0.32
- 3.0.31
- 3.0.30
- 3.0.29
- 3.0.28
- 3.0.27
- 3.0.26
- 3.0.25
- 3.0.24
- 3.0.23
- 3.0.22
- 3.0.21
- 3.0.20
- 3.0.19
- 3.0.18
- 3.0.17
- 3.0.16
- 3.0.15
- 3.0.14
- 3.0.13
- 3.0.12
- 3.0.11
- 3.0.10
- 3.0.9
- 3.0.8
- 3.0.6
- 3.0.5
- 3.0.3
- 3.0.2
- 3.0.1
- 3.0.0
- 2.1.1
- 2.1.0
- 2.0.0
- 1.5.0
- 1.4.0
- 1.3.0
- 1.2.1
- 0.19.0
- 0.18.0
- 0.17.0
- 0.16.0
- 0.1.0
- 0.0.9
- 0.0.8
- 0.0.7
- 0.0.6
- 0.0.5
- 0.0.4
- 0.0.3
- 0.0.2
- 0.0.1
- dev-dev/v9.0
- dev-develop
- dev-dev_haivd
This package is auto-updated.
Last update: 2022-06-17 10:31:34 UTC
README
Category management package for managing category in laravel framework
Installation
Composer
To include the package in your project, Please run following command.
composer require vicoders/categorymanager
Service Provider
In your config/app.php
add the following Service Providers to the end of the providers
array:
'providers' => [ ... VCComponent\Laravel\Category\Providers\CategoryServiceProvider::class, VCComponent\Laravel\Category\Providers\CategoryRouteProvider::class, ],
Config and Migration
Run the following commands to publish configuration and migration files.
php artisan vendor:publish --provider="VCComponent\Laravel\Category\Providers\CategoryServiceProvider"
php artisan vendor:publish --provider="Dingo\Api\Provider\LaravelServiceProvider"
php artisan vendor:publish --provider "Prettus\Repository\Providers\RepositoryServiceProvider"
Create tables:
php artisan migrate
Environment
In .env
file, we need some configuration.
API_PREFIX=api
API_VERSION=v1
API_NAME="Your API Name"
API_DEBUG=false
Configuration
URL namespace
To avoid duplication with your application's api endpoints, the package has a default namespace for its routes which is category-management
. For example:
{{url}}/api/category-management/admin/categories
You can modify the package url namespace to whatever you want by modifying the CATEGORY_COMPONENT_NAMESPACE
variable in .env
file.
CATEGORY_COMPONENT_NAMESPACE="your-namespace"
Model and Transformer
You can use your own model and transformer class by modifying the configuration file config\category.php
'models' => [ 'category' => App\Entities\Category::class, ], 'transformers' => [ 'category' => App\Transformers\CategoryTransformer::class, ],
Your Category
model class must implements VCComponent\Laravel\Category\Contracts\CategorySchema
and VCComponent\Laravel\Category\Contracts\CategoryManagement
<?php namespace App\Entities; use Illuminate\Database\Eloquent\Model; use Prettus\Repository\Contracts\Transformable; use Prettus\Repository\Traits\TransformableTrait; use VCComponent\Laravel\Category\Contracts\CategoryManagement; use VCComponent\Laravel\Category\Contracts\CategorySchema; use VCComponent\Laravel\Category\Traits\CategoryManagementTrait; use VCComponent\Laravel\Category\Traits\CategorySchemaTrait; class Category extends Model implements Transformable, CategorySchema, CategoryManagement { use TransformableTrait, CategorySchemaTrait, CategoryManagementTrait; const STATUS_PENDING = 1; const STATUS_ACTIVE = 2; protected $fillable = [ 'name', 'slug', 'parent_id', 'type', 'type_post' ]; }
Auth middleware
Configure auth middleware in configuration file config\category.php
'auth_middleware' => [ 'admin' => [ 'middleware' => 'jwt.auth', 'except' => ['index'], ], 'frontend' => [ 'middleware' => 'jwt.auth', 'except' => ['index'], ], ],
Query functions provide
Repository
List of query functions
Get the list of categories of post type
public function getCategoriesQuery(array $where, $number = 10, $order_by ='order', $order = 'asc', $columns = ['*']); public function getCategoriesQueryPaginate(array $where, $number = 10, $order_by ='order', $order = 'asc', $columns = ['*']); // Get a list of categories of a paginated post type
Get the category list of an article
public function getPostCategoriesQuery($post_id, array $where, $post_type = 'posts', $number = 10, $order_by = 'order', $order = 'asc'); public function getPostCategoriesQueryPaginate($post_id, array $where, $post_type = 'posts', $number = 10, $order_by = 'order', $order = 'asc'); // get the category list of a paginated article
Use
At controller use CategoryRepository
and add function __construct
use VCComponent\Laravel\Category\Repositories\CategoryRepository;
public function __construct(CategoryRepository $categoryRepo) { $this->categoryRepo = $categoryRepo; }
For example
public function index() { $categories = $this->categoryRepo->getCategoriesQuery(['type'=>'knowledge'],0); // get all categories of post type knowledge (with $number = 0 get all records) $categoriesPaginate = $this->categoryRepo ->getCategoriesQueryPaginate(['type'=>'knowledge']); // get categories of paginated knowledge post type $postCategories = $this->categoryRepo->getPostCategoriesQuery(45,['status'=>1]); // retrieve the categories of posts id = 45 $postCategoriesPaginate = $this->categoryRepo ->getPostCategoriesQueryPaginate(45,['status'=>1]); // get the categories of posts id = 45 with pagination }
Entity
List of entity query functions
Scope a query to only include categories of a given type.
public function scopeOfType($query)
Scope a query to only include hot categories.
public function scopeIsHot($query)
Scope a query to only include published categories.
public function scopeIsPublished($query)
Scope a query to order categories by order column.
public function scopeSortByOrder($query, $order = 'acs')
Scope a query to order categories by name column.
public function scopeSortByName($query, $order = 'asc')
Scope a query to order categories by usage time. From hight to low.
public function scopeMostUsed($query, $categoryable_type = null)
Scope a query to order categories by usage time. From low to hight.
public function scopeLeastUsed($query, $categoryable_type = null)
Use entity query function
Use Trait.
namespace App\Model; use VCComponent\Laravel\Category\Traits\CategoryQueryTrait; class Category { use CategoryQueryTrait; \\ }
Extend VCComponent\Laravel\Category\Entities\Category
Entity.
namespace App\Model; use VCComponent\Laravel\Category\Entities\Category as BaseCategory; class Category extends BaseCategory { \\ }
Entity query function example
$category = Category::ofType('posts')->isHot()->isPublished()->mostUsed()->pageinate(15);
View
Your CategoryListController
controller class must extends VCComponent\Laravel\Category\Http\Controllers\Web\CategoryListController as BaseCategoryListController
implements VCComponent\Laravel\Category\Contracts\ViewCategoryListControllerInterface;
class CategoryListController extends BaseCategoryListController implements ViewCategoryListControllerInterface { }
Your CategoryDetailController
controller class must extends VCComponent\Laravel\Category\Http\Controllers\Web\CategoryDetailController as BaseCategoryDetailController
implements VCComponent\Laravel\Category\Contracts\ViewCategoryDetailControllerInterface;
class CategoryDetailController extends BaseCategoryDetailController implements ViewCategoryDetailControllerInterface { }
If you want change view default CategoryList
, CategoryDetail
, you must add the view your to the Category
controller class.
protected function view() { return 'view-custom'; }
Routes
The api endpoint should have these format:
Verb | URI |
---|---|
GET | /api/{namespace}/admin/categories |
GET | /api/{namespace}/admin/categories/{id} |
POST | /api/{namespace}/admin/categories |
PUT | /api/{namespace}/admin/categories/{id} |
DELETE | /api/{namespace}/admin/categories/{id} |
PUT | /api/{namespace}/admin/categories/status/bulk |
PUT | /api/{namespace}/admin/categories/status/{id} |
---- | ---- |
GET | /api/{namespace}/categories |
GET | /api/{namespace}/categories/{id} |
POST | /api/{namespace}/categories |
PUT | /api/{namespace}/categories/{id} |
DELETE | /api/{namespace}/categories/{id} |
PUT | /api/{namespace}/categories/status/bulk |
PUT | /api/{namespace}/categories/status/{id} |