<?php namespace App\Http\Controllers;

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

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

		    function __construct() {    
				$this->table       = "umkm_usaha";        
				$this->permalink   = "add_usaha";    
				$this->method_type = "post";    
		    }
		

		    public function hook_before(&$postdata) {
		       $warga = DB::table('warga_bjb')->where('nik',$postdata['warga_bjb_id'])->first();
		       $postdata['warga_bjb_id']=$warga->id;
		       
		       $mirip = DB::table('umkm_usaha')->where('nama_usaha','like','%'. $postdata['nama_usaha'] .'%')->where('warga_bjb_id',$warga->id)->first();
		       if($mirip){
		            $resp = response()->json(['api_stastus'=>0,'api_message'=>'Nama Usaha "' . $postdata['nama_usaha'] . '"  sudah ada ! Coba nama lain.']);
                    $resp->send();
                    exit;
		       }
		      // dd($postdata);

		    }

		    public function hook_query(&$query) {
		        //This method is to customize the sql query

		    }

		    public function hook_after($postdata,&$result) {
		        //This method will be execute after run the main process

		    }

		}