<?php namespace App\Http\Controllers;

		use Session;
		use Request;
		use DB;
		use CRUDBooster;

		class ApiListKategoriController extends \crocodicstudio\crudbooster\controllers\ApiController {

		    function __construct() {    
				$this->table       = "kategori_lokasi";        
				$this->permalink   = "list_kategori";    
				$this->method_type = "get";    
		    }
		

		    public function hook_before(&$postdata) {
		        //This method will be execute before run the main process

		    }

		    public function hook_query(&$query) {
		        //This method is to customize the sql query
		        $query->orderBy('id','asc');
		    }

		    public function hook_after($postdata,&$result) {
		        //This method will be execute after run the main process
				
				foreach($result['data'] as $data){
						
						$punya_anak = DB::Table('kategori_lokasi')->where('ortu',$data->id)->orderBy('id','asc')->get();
						if($punya_anak){
							$anaknya = array();
							foreach($punya_anak as $anak){
							    $anak->icon = "https://siapkk.banjarbarukota.go.id/". $anak->icon;
								array_push($anaknya, $anak);
							}
							$data->anak = $anaknya;							
						}
						
				}
				
				//$result['data'] = $result['data']->sortBy('id');
		    }

		}