Taxonomies

Purpose

Although taxonomies are a crucial component of categorising the material on your application, the phrase frequently confuses newcomers because Taxonomy isn't a term that most of us use on a daily basis. Taxonomy are really just a technique to group similar posts entries (or other types of content) together. That's it! It's a large term, but it's not as hard to understand as it would seem.

For example, if you manage a sports blog, you could create taxonomies for every sport (basketball, cricket, football, etc.) and assign relevant posts to each taxonomy.

Taxonomies are advantageous because they make it simpler for readers to locate relevant content (and also because they provide your content some context, though that is a secondary advantage).

Default Taxonomy Types

By default, VaahCMS have following types of Taxonomies:

  1. Countries
  2. Registrations

Features & Demos

Create Taxonomy and Taxonomy Types via VaahSeeder

Through seeds, you can create Taxonomy and Taxonomy types. Make two json files with the names taxonomy.json and taxonomy_types.json in the directory ../VaahCms/Modules/<module-name>/Database/Seeds/json/.

NOTE:
You need to make a directory named as json under ../VaahCms/Modules/<module-name>/Database/Seeds.

taxonomy.json

[

    {
        "type_slug": "roles",
        "name": "Backend"
    },
    {
        "type_slug": "roles",
        "name": "Frontend"
    },
    {
        "type_slug": "registrations",
        "name": "Email Verification Pending"
    }
]

taxonomy_types.json

[

    {
        "name": "Countries"
    },

    {
        "name": "Cities",
        "parent_slug": "countries"
    },

    {
        "name": "Roles"
    }
]

In order to run these seeds you need to add these lines in run() method of DatabaseTableSeeder.php file

VaahSeeder::taxonomyTypes(__DIR__.'/json/taxonomy_types.json');
VaahSeeder::taxonomies(__DIR__.'/json/taxonomy.json');

DatabaseTableSeeder.php

<?php
namespace VaahCms\Modules\{module_name}\Database\Seeds;


use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Str;
use WebReinvent\VaahCms\Libraries\VaahSeeder;

class DatabaseTableSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        VaahSeeder::taxonomyTypes(__DIR__.'/json/taxonomy_types.json');
        VaahSeeder::taxonomies(__DIR__.'/json/taxonomy.json');
    }

}

Now you need to login to the backend and activate your module again by first deactivating it.


Create Taxonomy via Dashboard

To view the Taxonomies section, go to the following url:

<project-url>/backend#/vaah/manage/taxonomies/

Follow below image for reference:

You can create a new taxonomy by clicking on Create button. When you click on Create button you will see a form with following fields. Type is the first field, and the options are organised hierarchically. You can manage the taxonomy types also by clicking on the Manage button. The Tree View of Taxonomy Types PopUp with 'CRUD' Operation will now show.

You will notice a new field called Select a Parent name with the taxonomies of the parent of the type you have chosen if you choose any of the children types.

Complete every field and press the Create & New button. A new taxonomy will be added to the list of taxonomies.

You can view the video attached below for more info:

Create Taxonomy Type via Dashboard

To create a new Taxonomy Type you need to click on Manage button.

Follow below image for reference:

When you click on manage button a PopUp will open with the following fields.

Here in the Select a Parent dropdown you need to select a parent for the new taxonomy type that we are going to create. You also need to provide the name of the taxonomy type.

Once you filled these details you need to click on Add button. A new taxonomy type will be showm to you in the same page.

Watch the below video for better understanding

Permissions

The following permissions are necessary for Taxonomies and Taxonomy Type management in order to carry out certain actions.

PermissionsDescription
Can Manage TaxonomiesThis permission enables roles to manage taxonomies. The user can activate, deactivate, update or delete a taxonomy with this access.
Can Delete TaxonomiesThis permission grants roles access to delete a taxonomy.
Can Update TaxonomiesThis permission grants roles to update details of a taxonomy.
Can Read TaxonomiesThis permission grants roles to read all listed taxonomies of the application.
Can Create TaxonomiesThis permission grant roles to create a new taxonomy for the application.
Has Access Of Taxonomies SectionThis permission grant roles to access of the taxonomies section in the side nav bar of the application.
Can Manage Taxonomy TypesThis permission grant roles to manage or perform CRUD operation on the Taxonomy Type.

Files

  • Laravel Route: vaahcms/Routes/backend/route-texonomies.php
  • Laravel Controller: vaahcms/Http/Controllers/Backend/TaxonomiesController.php
  • Laravel Model: vaahcms/Models/Taxonomy.php
  • Vue Route: vaahcms/Vue/routes/vue-routes-taxonomies.js
  • Vue Store: vaahcms/Vue/stores/store-taxonomies.js
  • Vue Page Directory: vaahcms/Vue/pages/taxonomies

Methods

Some reusable method of Taxonomy and TaxonomyType mentioned bellowed:

TaxonomyType::getTaxonomyByType($type)

You can use this method to retrieve all taxonomies that are currently active under given TaxonomyType by just giving the desired TaxonomyType slug.

use WebReinvent\VaahCms\Models\Taxonomy;  // Import Taxonomy class at the top

$taxonomy_type_slug = 'cities';
return $active_taxonomies = Taxonomy::getTaxonomyByType($taxonomy_type_slug);

PermissionsDescription
Can Manage TaxonomiesThis permission enables roles to manage taxonomies. The user can activate, deactivate, update or delete a taxonomy with this access.
Can Delete TaxonomiesThis permission grants roles access to delete a taxonomy.
Can Update TaxonomiesThis permission grants roles to update details of a taxonomy.
Can Read TaxonomiesThis permission grants roles to read all listed taxonomies of the application.
Can Create TaxonomiesThis permission grant roles to create a new taxonomy for the application.
Has Access Of Taxonomies SectionThis permission grant roles to access of the taxonomies section in the side nav bar of the application.
Can Manage Taxonomy TypesThis permission grant roles to manage or perform CRUD operation on the Taxonomy Type.

API

VaahCMS has APIs for every method, allowing you to interact with NuxJS or other frameworks.

You can access APIs method from vaachms/Http/Controllers/Api/TaxonomiesController.php and routes from vaahcms/Routes/api/api-routes-taxonomies.php

We mention some methods bellow which help you to understand the structure.

Create Taxonomy

Method: POST
Action: creatItem
URL: <public-url>/api/vaah/manage/taxonomies/
Sample Request
parameter = [
    'type',              //required
    'name',              //required
    'slug',              //required
    'is_active'          //required
    'note',              //optional
    'seo_title'          //optional
    'seo_keywords'       //optional
    'seo_description'    //optional
];
Sample Response
{
  "data": {
    "item": {
      ...
    }
  },
  "messages": [
    "Saved successfully."
  ],
  "success": "true"
}

Fetch Taxonomies

Method: GET
Action: getList
URL: <public-url>/api/vaah/manage/taxonomies/
Sample Request
parameter = [
    'filter' => [
        'q'            // for search queary (optionl)
        'trashed'      // for include or exclude trashed data (optionl)
        'is_active'    // for fetching only active or inactive data (optionl)
        'sort'         // for sorting the data (optionl)
    ];  
];
Sample Response
{
  "data": {
    "data" : {
      ...
    }
  }
}

Fetch Single Taxonomy

Method: GET
Action: getItem
URL: <public-url>/api/vaah/manage/taxonomies/{id}
Sample Response
{
  "data": {
      ...
  },
  "success": "true"
}