<?php namespace App\Http\Controllers;

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

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

		    function __construct() {    
				$this->table       = "kategori_produk";        
				$this->permalink   = "kategori_produk";    
				$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

		    }

		    public function hook_after($postdata,&$result) {
		        if($result["api_status"]==1){
		            foreach($result["data"] as $data){
		                $count = DB::table("produk")->where("kategori_produk_id",$data->id)->count();
		                $data->numOfProduk = $count;
		                if($data->icon){
		                    $data->icon = CRUDBooster::publicPath($data->icon);
		                }else{
		                    $data->icon = CRUDBooster::publicPath("others/noimage.svg");
		                }
		                if(!$data->banner){
		                     $data->banner = CRUDBooster::publicPath("others/noimage.jpg");
		                }
		                if(!$data->photo){
		                     $data->photo = CRUDBooster::publicPath("others/noimage.jpg");
		                }
		            }
		        }
		    }

		}