<?php namespace App\Http\Controllers;

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

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

		    function __construct() {    
				$this->table       = "peraturan";        
				$this->permalink   = "detail_dokumen";    
				$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){
    		        $subjek = DB::table('peraturan_subjek')->join('subjek','subjek.id','peraturan_subjek.id_subjek')->where('peraturan_subjek.id_peraturan',$result['id'])->pluck('subjek.subjek');
                    $result['subjek'] = $subjek;
                    $bidang_hukum = DB::table('peraturan_bidang_hukum')->join('bidang_hukum','bidang_hukum.id','peraturan_bidang_hukum.id_bidang_hukum')->where('peraturan_bidang_hukum.id_peraturan',$result['id'])->pluck('bidang_hukum.bidang_hukum');
                    $result['bidang_hukum'] = $bidang_hukum;
                    $jenis = DB::table('tipe_dokumen')->where('id',$result['jenis_id'])->first();
                    $result['jenis'] = $jenis->nama;
                    $result['parent'] = $jenis->parent_id;
                    $jenis = DB::table('bahasa')->where('id',$result['bahasa_id'])->first();
                    $result['bahasa'] = $jenis->bahasa;
                    $jenis = DB::table('lokasi_dokumen')->where('id',$result['lokasi_id'])->first();
                    $result['lokasi'] = $jenis->lokasi_dokumen;
                    $terkait = DB::table('peraturan_terkait')->join('peraturan','peraturan.id','peraturan_terkait.id_peraturan')->where('peraturan_id',$result['id'])->get();
                    $result['terkait'] = $terkait;
		        }
		    }

		}