Skip to content

Latest commit

 

History

History
111 lines (70 loc) · 2.5 KB

Category.md

File metadata and controls

111 lines (70 loc) · 2.5 KB

Categories

Introduction

By default, english language will be used. In order to use Nepali language, you have to specify while initiating the category object.

<?php

use Sagautam5\LocalStateNepal\Entities\Category;

// English language will be selected by default
$category = new Category();

You can specify language like this:

<?php

use Sagautam5\LocalStateNepal\Entities\Category;

$category = new Category('np');

Retrieving Categories

Once you initiate category entity, you can retrieve variety of data.

  1. Get list of all categories

    <?php
    
    use Sagautam5\LocalStateNepal\Entities\Category;
    
    $category = new Category();
    
    $categoryList = $category->allCategories();
  2. Find category details by unique identifier

    <?php
    
    use Sagautam5\LocalStateNepal\Entities\Category;
    
    $category = new Category();
    
    $categoryDetails = $category->find(1);
  3. Find category details by short code

    <?php
    
    use Sagautam5\LocalStateNepal\Entities\Category;
    
    $category = new Category();
    
    // Options: MC, SMC, M, RM
    $categoryDetails = $category->findByShortCode('MC');
  4. Search categories by key and value with exact match option

     <?php
     
     use Sagautam5\LocalStateNepal\Entities\Category;
     
     $category = new Category();
    
     $categoryDetails = $category->search('name', 'Municipality');
    
     // For exact match, pass optional parameter $exact as true 
     $categoryDetails = $category->search('name', 'Municipality', true);

    List of options for parameter key:

        ['id', 'name', 'short_code']
  5. Recursive search with multiple set of key value data

     <?php
     
     use Sagautam5\LocalStateNepal\Entities\Category;
     
     $category = new Category();
     $params = [
                    ['key' => 'name', 'value' => 'some name', 'exact' => false],   
                    ['key' => 'id', 'value' => 'some id', 'exact' => true]
        ];
     $categoryDetails = $category->recursiveSearch($params);   
    
     // if you have already filtered category data in structured format, then you can pass the data in recursive search
     $data =  $category->search('name', 'some name', false); 
    
     $categoryDetails = $category->search($params, $data);

    List of options for parameter key:

    ['id', 'name', 'short_code']