<file_sep><?php namespace App\Domain\Entities\Kependudukan;

use Illuminate\Database\Eloquent\Model;

class Keluarga extends Model
{
    /**
     * @var string
     */
    protected $table = 'keluarga';

    /**
     * @var array
     */
    protected $fillable = [
        'nik_kk',
        'nama_kk',
        'alamat',
        'rt',
        'rw',
        'dusun',
        'telepon',
        'status',
    ];

    /**
     * @var string
     */
    public static $tags = 'keluarga';

    /**
     * The attributes that aren't mass assignable.
     *
     * @var array
     */
    protected $hidden = [
        'created_at',
        'updated_at'
    ];
}
<file_sep><?php

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateTableMutasi extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('mutasi', function (Blueprint $table) {
            $table->engine = 'InnoDB';
            $table->increments('id');
            $table->string('nik', 16)->unique();
            $table->string('alamat', 1);
            $table->string('rt', 3);
            $table->string('rw', 20);
            $table->string('dusun');
            $table->integer('desa_id');
            $table->boolean('status')->default(0);
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::drop('mutasi');
    }
}
<file_sep><?php namespace App\Http\Requests\Kependudukan;

use App\Http\Requests\Request;
use Illuminate\Contracts\Validation\Validator;

class OrtuFormRequest extends Request
{
    /**
     * @var array
     */
    protected $attrs = [
        'nik'          => 'NIK',
        'nik_bapak'    => 'NIK Bapak',
        'nama_bapak'   => '<NAME>',
        'status_bapak' => 'Status Bapak',
        'alamat_bapak' => 'Alamat Bapak',
        'nik_ibu'      => 'NIK Ibu',
        'nama_ibu'     => 'Nama Ibu',
        'status_ibu'   => 'Status Ibu',
        'alamat_ibu'   => 'Alamat Ibu',
    ];

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'nik'          => 'required|max:16|unique:ortu,nik',
            'nik_bapak'    => 'required|max:16',
            'nama_bapak'   => 'required|max:50',
            'status_bapak' => 'required|max:25',
            'alamat_bapak' => 'required|max:50',
            'nik_ibu'      => 'required|max:16',
            'nama_ibu'     => 'required|max:50',
            'status_ibu'   => 'required|max:25',
            'alamat_ibu'   => 'required|max:50',
        ];
    }

    /**
     * @param $validator
     *
     * @return mixed
     */
    public function validator($validator)
    {
        return $validator->make($this->all(), $this->container->call([$this, 'rules']), $this->messages(), $this->attrs);
    }

    /**
     * @param Validator $validator
     *
     * @return array
     */
    protected function formatErrors(Validator $validator)
    {
        $message = $validator->errors();

        return [
            'success'    => false,
            'validation' => [
                'nik'          => $message->first('nik'),
                'nik_bapak'    => $message->first('nik_bapak'),
                'nama_bapak'   => $message->first('nama_bapak'),
                'status_bapak' => $message->first('status_bapak'),
                'alamat_bapak' => $message->first('alamat_bapak'),
                'nik_ibu'      => $message->first('nik_ibu'),
                'nama_ibu'     => $message->first('nama_ibu'),
                'status_ibu'   => $message->first('status_ibu'),
                'alamat_ibu'   => $message->first('alamat_ibu'),
            ]
        ];
    }
}
<file_sep><?php namespace App\Http\Requests\Kependudukan;

use App\Http\Requests\Request;
use Illuminate\Contracts\Validation\Validator;

class PribadiRincianFormRequest extends Request
{
    /**
     * @var array
     */
    protected $attrs = [
        'nik'            => 'NIK',
        'kelainan_fisik' => 'Kelainan Fisik',
        'cacat_fisik'    => 'Cacat Fisik',
        'warga_negara'   => 'Warga Negara',
        'website'        => 'Website',
        'email'          => 'Email',
        'telp'           => 'Telepon',
    ];

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'nik'            => 'required|max:16|unique:pribadi_rincian,nik',
            'kelainan_fisik' => 'max:100',
            'cacat_fisik'    => 'max:100',
            'warga_negara'   => 'required|max:30',
            'website'        => 'max:80|url',
            'email'          => 'max:80|email',
            'telp'           => 'max:15',
        ];
    }

    /**
     * @param $validator
     *
     * @return mixed
     */
    public function validator($validator)
    {
        return $validator->make($this->all(), $this->container->call([$this, 'rules']), $this->messages(), $this->attrs);
    }

    /**
     * @param Validator $validator
     *
     * @return array
     */
    protected function formatErrors(Validator $validator)
    {
        $message = $validator->errors();

        return [
            'success'    => false,
            'validation' => [
                'nik'            => $message->first('nik'),
                'kelainan_fisik' => $message->first('kelainan_fisik'),
                'cacat_fisik'    => $message->first('cacat_fisik'),
                'warga_negara'   => $message->first('warga_negara'),
                'website'        => $message->first('website'),
                'email'          => $message->first('email'),
                'telp'           => $message->first('telp'),
            ]
        ];
    }
}
<file_sep><?php namespace App\Domain\Entities\Kependudukan;

use Illuminate\Database\Eloquent\Model;

class Ortu extends Model
{
    /**
     * @var string
     */
    protected $table = 'ortu';

    /**
     * @var array
     */
    protected $fillable = [
        'nik',
        'nik_bapak',
        'nama_bapak',
        'status_bapak',
        'alamat_bapak',
        'nik_ibu',
        'nama_ibu',
        'status_ibu',
        'alamat_ibu',
        'status',
    ];

    /**
     * @var string
     */
    public static $tags = 'ortu';

    /**
     * The attributes that aren't mass assignable.
     *
     * @var array
     */
    protected $hidden = [
        'created_at',
        'updated_at'
    ];
}
<file_sep><?php

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateTablePribadi extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('pribadi', function (Blueprint $table) {
            $table->engine = 'InnoDB';
            $table->increments('id');
            $table->string('keluarga_id', 18);
            $table->string('nik', 25)->unique();
            $table->string('title_depan', 20)->nullable();
            $table->string('title_belakang', 20)->nullable();
            $table->string('nama');
            $table->string('kelamin');
            $table->string('tempat_lahir');
            $table->string('tanggal_lahir');
            $table->string('golongan_darah')->nullable();
            $table->string('agama');
            $table->string('status_kawin');
            $table->string('status_keluarga');
            $table->string('pendidikan')->nullable();
            $table->string('pekerjaan')->nullable();
            $table->boolean('status')->default(0);
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::drop('pribadi');
    }
}
<file_sep><?php namespace App\Http\Controllers\Kependudukan;

use App\Domain\Repositories\Kependudukan\KeluargaRepository;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use App\Http\Requests\Kependudukan\KeluargaFormRequest;

class KeluargaController extends Controller
{

    /**
     * @var KeluargaRepository
     */
    protected $keluarga;

    /**
     * @param KeluargaRepository $keluarga
     */
    public function __construct(KeluargaRepository $keluarga)
    {
        $this->keluarga = $keluarga;
//        $this->middleware('auth');
    }

    /**
     * Display a listing of the resource.
     *
     * @param Request $request
     *
     * @return mixed
     */
    public function index(Request $request)
    {
        return $this->keluarga->getByPage(10, $request->input('page'), $column = ['*'], $key = '', $request->input('term'));
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  KeluargaFormRequest $request
     *
     * @return mixed
     */
    public function store(KeluargaFormRequest $request)
    {
        return $this->keluarga->create($request->all());
    }

    /**
     * Display the specified resource.
     *
     * @param  int $id
     *
     * @return mixed
     */
    public function show($id)
    {
        return $this->keluarga->find($id);
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  KeluargaFormRequest $request
     * @param  int                 $id
     *
     * @return mixed
     */
    public function update(KeluargaFormRequest $request, $id)
    {
        return $this->keluarga->update($id, $request->all());
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int $id
     *
     * @return mixed
     */
    public function destroy($id)
    {
        return $this->keluarga->delete($id);
    }
}
<file_sep><?php

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateTableKabkot extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('kabkot', function (Blueprint $table) {
            $table->engine = 'InnoDB';
            $table->increments('id');
            $table->integer('provinsi_id');
            $table->string('kode_kabupaten', 3);
            $table->string('kabupaten');
            $table->integer('is_status');
            $table->string('waktu', 4);
            $table->integer('pbb_kabukot_kode');
            $table->integer('arsip_kabukot_kode');
            $table->integer('kodepos_kabukot_kode');
            $table->integer('ramil_kabukot_kode');
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::drop('kabkot');
    }
}
<file_sep><?php namespace App\Domain\Repositories\Kependudukan;

use App\Domain\Contracts\Cacheable;
use App\Domain\Contracts\Crudable;
use App\Domain\Contracts\Paginable;
use App\Domain\Entities\Kependudukan\Pribadi;
use App\Domain\Repositories\AbstractRepository;
use Illuminate\Support\Facades\Log;

class PribadiRepository extends AbstractRepository implements Crudable, Paginable
{
    /**
     * @var Cacheable
     */
    protected $cache;

    /**
     * @param Pribadi   $pribadi
     * @param Cacheable $cache
     */
    public function __construct(Pribadi $pribadi, Cacheable $cache)
    {
        $this->model = $pribadi;
        $this->cache = $cache;
    }

    /**
     * @param int   $id
     * @param array $columns
     *
     * @return \Illuminate\Database\Eloquent\Model
     */
    public function find($id, array $columns = ['*'])
    {
        // set key
        $key = 'pribadi-find-' . $id;

        // has section and key
        if ($this->cache->has(Pribadi::$tags, $key)) {
            return $this->cache->get(Pribadi::$tags, $key);
        }

        // query to sql
        $result = parent::find($id, $columns);

        // store to cache
        $this->cache->put(Pribadi::$tags, $key, $result, 10);

        return $result;
    }

    /**
     * @param array $data
     *
     * @return \Symfony\Component\HttpFoundation\Response
     */
    public function create(array $data)
    {
        try {

            // execute sql insert
            $result = parent::create([
                'keluarga_id'     => e($data['keluarga_id']),
                'nik'             => e($data['nik']),
                'title_depan'     => (empty($data['title_depan'])) ? null : e($data['title_depan']),
                'title_belakang'  => (empty($data['title_belakang'])) ? null : e($data['title_belakang']),
                'nama'            => e($data['nama']),
                'kelamin'         => e($data['kelamin']),
                'tempat_lahir'    => e($data['tempat_lahir']),
                'tanggal_lahir'   => e($data['tanggal_lahir']),
                'golongan_darah'  => (empty($data['golongan_darah'])) ? null : e($data['golongan_darah']),
                'agama'           => e($data['agama']),
                'status_kawin'    => e($data['status_kawin']),
                'status_keluarga' => e($data['status_keluarga']),
                'pendidikan'      => (empty($data['pendidikan'])) ? null : e($data['pendidikan']),
                'pekerjaan'       => (empty($data['pekerjaan'])) ? null : e($data['pekerjaan']),
                'status'          => (empty($data['status'])) ? '0' : e($data['status']),
            ]);

            // flush cache with tags
            $this->cache->flush(Pribadi::$tags);

            return $result;

        } catch (\Exception $e) {
            // store errors to log
            Log::error('class : ' . PribadiRepository::class . ' method : create | ' . $e);

            return $this->createError();
        }

    }

    /**
     * @param       $id
     * @param array $data
     *
     * @return \Symfony\Component\HttpFoundation\Response
     */
    public function update($id, array $data)
    {
        try {
            $result = parent::update($id, [
                'keluarga_id'     => e($data['keluarga_id']),
                'nik'             => e($data['nik']),
                'title_depan'     => (empty($data['title_depan'])) ? null : e($data['title_depan']),
                'title_belakang'  => (empty($data['title_belakang'])) ? null : e($data['title_belakang']),
                'nama'            => e($data['nama']),
                'kelamin'         => e($data['kelamin']),
                'tempat_lahir'    => e($data['tempat_lahir']),
                'tanggal_lahir'   => e($data['tanggal_lahir']),
                'golongan_darah'  => (empty($data['golongan_darah'])) ? null : e($data['golongan_darah']),
                'agama'           => e($data['agama']),
                'status_kawin'    => e($data['status_kawin']),
                'status_keluarga' => e($data['status_keluarga']),
                'pendidikan'      => (empty($data['pendidikan'])) ? null : e($data['pendidikan']),
                'pekerjaan'       => (empty($data['pekerjaan'])) ? null : e($data['pekerjaan']),
                'status'          => (empty($data['status'])) ? '0' : e($data['status']),
            ]);

            // flush cache with tags
            $this->cache->flush(Pribadi::$tags);

            return $result;

        } catch (\Exception $e) {
            // store errors to log
            Log::error('class : ' . PribadiRepository::class . ' method : update | ' . $e);

            return $this->createError();
        }
    }

    /**
     * @param $id
     *
     * @return \Symfony\Component\HttpFoundation\Response
     */
    public function delete($id)
    {
        try {
            $result = parent::delete($id);

            // flush cache with tags
            $this->cache->flush(Pribadi::$tags);

            return $result;

        } catch (\Exception $e) {
            // store errors to log
            Log::error('class : ' . PribadiRepository::class . ' method : delete | ' . $e);

            return $this->createError();
        }
    }

    /**
     * @param int    $limit
     * @param int    $page
     * @param array  $column
     * @param string $field
     * @param string $search
     *
     * @return \Illuminate\Pagination\Paginator
     */
    public function getByPage($limit = 10, $page = 1, array $column = ['*'], $field, $search = '')
    {
        // set key
        $key = 'pribadi-get-by-page-' . $page . $limit . $search;

        // has section and key
        if ($this->cache->has(Pribadi::$tags, $key)) {
            return $this->cache->get(Pribadi::$tags, $key);
        }

        // query to sql
        $result = parent::getByPageOrderBy($limit, $page, $column, 'nik', $search, 'nama');

        // store to cache
        $this->cache->put(Pribadi::$tags, $key, $result, 10);

        return $result;
    }

}
<file_sep><?php

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateTableOrtu extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('ortu', function (Blueprint $table) {
            $table->engine = 'InnoDB';
            $table->increments('id');
            $table->string('nik', 16)->unique();
            $table->string('nik_bapak', 16)->unique();
            $table->string('nama_bapak', 55);
            $table->string('status_bapak', 30);
            $table->string('alamat_bapak', 55);
            $table->string('nik_ibu', 16)->unique();
            $table->string('nama_ibu', 55);
            $table->string('status_ibu', 30);
            $table->string('alamat_ibu', 55);
            $table->boolean('status')->default(0);
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::drop('ortu');
    }
}
<file_sep><?php namespace App\Domain\Entities\Kependudukan;

use Illuminate\Database\Eloquent\Model;

class Pribadi extends Model
{
    /**
     * @var string
     */
    protected $table = 'pribadi';

    /**
     * @var array
     */
    protected $fillable = [
        'keluarga_id',
        'nik',
        'title_depan',
        'title_belakang',
        'nama',
        'kelamin',
        'tempat_lahir',
        'tanggal_lahir',
        'golongan_darah',
        'agama',
        'status_kawin',
        'status_keluarga',
        'pendidikan',
        'pekerjaan',
        'status',
    ];

    /**
     * @var string
     */
    public static $tags = 'pribadi';

    /**
     * The attributes that aren't mass assignable.
     *
     * @var array
     */
    protected $hidden = [
        'created_at',
        'updated_at'
    ];
}
<file_sep><?php namespace App\Http\Controllers\Kependudukan;

use App\Domain\Repositories\Kependudukan\PribadiRincianRepository;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use App\Http\Requests\Kependudukan\PribadiRincianFormRequest;

class PribadiRincianController extends Controller
{
    /**
     * @var PribadiRincianRepository
     */
    protected $pribadi;

    /**
     * @param PribadiRincianRepository $pribadi
     */
    public function __construct(PribadiRincianRepository $pribadi)
    {
        $this->pribadi = $pribadi;
//        $this->middleware('auth');
    }

    /**
     * Display a listing of the resource.
     *
     * @param Request $request
     *
     * @return mixed
     */
    public function index(Request $request)
    {
        return $this->pribadi->getByPage(10, $request->input('page'), $column = ['*'], $key = '', $request->input('term'));
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  PribadiRincianFormRequest $request
     *
     * @return mixed
     */
    public function store(PribadiRincianFormRequest $request)
    {
        return $this->pribadi->create($request->all());
    }

    /**
     * Display the specified resource.
     *
     * @param  int $id
     *
     * @return mixed
     */
    public function show($id)
    {
        return $this->pribadi->find($id);
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  PribadiRincianFormRequest $request
     * @param  int                       $id
     *
     * @return mixed
     */
    public function update(PribadiRincianFormRequest $request, $id)
    {
        return $this->pribadi->update($id, $request->all());
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int $id
     *
     * @return mixed
     */
    public function destroy($id)
    {
        return $this->pribadi->delete($id);
    }
}
<file_sep><?php namespace App\Domain\Entities\Kependudukan;

use Illuminate\Database\Eloquent\Model;

class PribadiRincian extends Model
{
    /**
     * @var string
     */
    protected $table = 'pribadi_rincian';

    /**
     * @var array
     */
    protected $fillable = [
        'nik',
        'kelainan_fisik',
        'cacat_fisik',
        'warga_negara',
        'website',
        'email',
        'telp',
        'status',
    ];

    /**
     * @var string
     */
    public static $tags = 'pribadi-rincian';

    /**
     * The attributes that aren't mass assignable.
     *
     * @var array
     */
    protected $hidden = [
        'created_at',
        'updated_at'
    ];
}
<file_sep><?php namespace App\Http\Controllers\Kependudukan;

use App\Domain\Repositories\Kependudukan\OrtuRepository;
use App\Domain\Repositories\Kependudukan\PribadiRepository;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use App\Http\Requests\Kependudukan\OrtuFormRequest;

class OrtuController extends Controller
{
    /**
     * @var PribadiRepository
     */
    protected $ortu;

    /**
     * @param OrtuRepository $ortu
     */
    public function __construct(OrtuRepository $ortu)
    {
        $this->ortu = $ortu;
//        $this->middleware('auth');
    }

    /**
     * Display a listing of the resource.
     *
     * @param Request $request
     *
     * @return mixed
     */
    public function index(Request $request)
    {
        return $this->ortu->getByPage(10, $request->input('page'), $column = ['*'], $key = '', $request->input('term'));
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  OrtuFormRequest $request
     *
     * @return mixed
     */
    public function store(OrtuFormRequest $request)
    {
        return $this->ortu->create($request->all());
    }

    /**
     * Display the specified resource.
     *
     * @param  int $id
     *
     * @return mixed
     */
    public function show($id)
    {
        return $this->ortu->find($id);
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  OrtuFormRequest $request
     * @param  int             $id
     *
     * @return mixed
     */
    public function update(OrtuFormRequest $request, $id)
    {
        return $this->ortu->update($id, $request->all());
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int $id
     *
     * @return mixed
     */
    public function destroy($id)
    {
        return $this->ortu->delete($id);
    }
}
<file_sep><?php namespace App\Domain\Repositories\Kependudukan;

use App\Domain\Contracts\Cacheable;
use App\Domain\Contracts\Crudable;
use App\Domain\Contracts\Paginable;
use App\Domain\Entities\Kependudukan\Keluarga;
use App\Domain\Repositories\AbstractRepository;
use Illuminate\Support\Facades\Log;

class KeluargaRepository extends AbstractRepository implements Crudable, Paginable
{
    /**
     * @var Cacheable
     */
    protected $cache;

    /**
     * @param Keluarga  $keluarga
     * @param Cacheable $cache
     */
    public function __construct(Keluarga $keluarga, Cacheable $cache)
    {
        $this->model = $keluarga;
        $this->cache = $cache;
    }

    /**
     * @param int   $id
     * @param array $columns
     *
     * @return \Illuminate\Database\Eloquent\Model
     */
    public function find($id, array $columns = ['*'])
    {
        // set key
        $key = 'keluarga-find-' . $id;

        // has section and key
        if ($this->cache->has(Keluarga::$tags, $key)) {
            return $this->cache->get(Keluarga::$tags, $key);
        }

        // query to sql
        $result = parent::find($id, $columns);

        // store to cache
        $this->cache->put(Keluarga::$tags, $key, $result, 10);

        return $result;
    }

    /**
     * @param array $data
     *
     * @return \Symfony\Component\HttpFoundation\Response
     */
    public function create(array $data)
    {
        try {

            // execute sql insert
            $result = parent::create([
                'nik_kk'  => e($data['nik_kk']),
                'nama_kk' => e($data['nama_kk']),
                'alamat'  => e($data['alamat']),
                'rt'      => e($data['rt']),
                'rw'      => e($data['rw']),
                'dusun'   => e($data['dusun']),
                'telepon' => (empty($data['telepon'])) ? null : e($data['telepon']),
                'status'  => (empty($data['status'])) ? '0' : e($data['status']),
            ]);

            // flush cache with tags
            $this->cache->flush(Keluarga::$tags);

            return $result;

        } catch (\Exception $e) {
            // store errors to log
            Log::error('class : ' . KeluargaRepository::class . ' method : create | ' . $e);

            return $this->createError();
        }

    }

    /**
     * @param       $id
     * @param array $data
     *
     * @return \Symfony\Component\HttpFoundation\Response
     */
    public function update($id, array $data)
    {
        try {
            $result = parent::update($id, [
                'nik_kk'  => e($data['nik_kk']),
                'nama_kk' => e($data['nama_kk']),
                'alamat'  => e($data['alamat']),
                'rt'      => e($data['rt']),
                'rw'      => e($data['rw']),
                'dusun'   => e($data['dusun']),
                'telepon' => e($data['telepon']),
                'status'  => (empty($data['status'])) ? '0' : e($data['status']),
            ]);

            // flush cache with tags
            $this->cache->flush(Keluarga::$tags);

            return $result;

        } catch (\Exception $e) {
            // store errors to log
            Log::error('class : ' . KeluargaRepository::class . ' method : update | ' . $e);

            return $this->createError();
        }
    }

    /**
     * @param $id
     *
     * @return \Symfony\Component\HttpFoundation\Response
     */
    public function delete($id)
    {
        try {
            $result = parent::delete($id);

            // flush cache with tags
            $this->cache->flush(Keluarga::$tags);

            return $result;

        } catch (\Exception $e) {
            // store errors to log
            Log::error('class : ' . KeluargaRepository::class . ' method : delete | ' . $e);

            return $this->createError();
        }
    }

    /**
     * @param int    $limit
     * @param int    $page
     * @param array  $column
     * @param string $field
     * @param string $search
     *
     * @return \Illuminate\Pagination\Paginator
     */
    public function getByPage($limit = 10, $page = 1, array $column = ['*'], $field, $search = '')
    {
        // set key
        $key = 'keluarga-get-by-page-' . $page . $limit . $search;

        // has section and key
        if ($this->cache->has(Keluarga::$tags, $key)) {
            return $this->cache->get(Keluarga::$tags, $key);
        }

        // query to aql
        $result = parent::getByPageOrderBy($limit, $page, $column, 'nik_kk', $search, 'nama_kk');

        // store to cache
        $this->cache->put(Keluarga::$tags, $key, $result, 10);

        return $result;
    }

}
<file_sep><?php

use Illuminate\Database\Seeder;

class ProvinsiSeeder extends Seeder

{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        DB::table('provinsi')->truncate();
        DB::table('provinsi')->insert([
            ['id' => 1, 'kode_provinsi' => '35', 'provinsi' => 'Jawa Timur', 'pbb_prov_kode' => '', 'arsip_prov_kode' => '', 'kodepos_prov_kode' => '', 'ramil_prov_kode' => '', 'created_at' => \Carbon\Carbon::now()],
        ]);
    }
}
<file_sep><?php

namespace App\Http\Controllers;

use Dingo\Api\Http\Request;
use Dingo\Api\Exception\ValidationHttpException;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;

/**
 * Class Controller
 *
 * @package App\Http\Controllers
 */
abstract class Controller extends BaseController
{
    use AuthorizesRequests, ValidatesRequests;

    /**
     * @param Request $request
     * @param array   $rules
     * @param array   $messages
     * @param array   $customAttributes
     */
    public function validate(Request $request, array $rules, array $messages = [], array $customAttributes = [])
    {
        $validator = $this->getValidationFactory()->make($request->all(), $rules, $messages, $customAttributes);

        if ($validator->fails()) {
            throw new ValidationHttpException($validator->errors());
        }
    }
}
<file_sep><?php namespace App\Domain\Repositories\Kependudukan;

use App\Domain\Contracts\Cacheable;
use App\Domain\Contracts\Crudable;
use App\Domain\Contracts\Paginable;
use App\Domain\Entities\Kependudukan\Ortu;
use App\Domain\Entities\Kependudukan\Pribadi;
use App\Domain\Repositories\AbstractRepository;
use Illuminate\Support\Facades\Log;

class OrtuRepository extends AbstractRepository implements Crudable, Paginable
{
    /**
     * @var Cacheable
     */
    protected $cache;

    /**
     * @param Ortu      $ortu
     * @param Cacheable $cache
     */
    public function __construct(Ortu $ortu, Cacheable $cache)
    {
        $this->model = $ortu;
        $this->cache = $cache;
    }

    /**
     * @param int   $id
     * @param array $columns
     *
     * @return \Illuminate\Database\Eloquent\Model
     */
    public function find($id, array $columns = ['*'])
    {
        // set key
        $key = 'ortu-find-' . $id;

        // has section and key
        if ($this->cache->has(Ortu::$tags, $key)) {
            return $this->cache->get(Ortu::$tags, $key);
        }

        // query to sql
        $result = parent::find($id, $columns);

        // store to cache
        $this->cache->put(Ortu::$tags, $key, $result, 10);

        return $result;
    }

    /**
     * @param array $data
     *
     * @return \Symfony\Component\HttpFoundation\Response
     */
    public function create(array $data)
    {
        try {

            // execute sql insert
            $result = parent::create([
                'nik'          => e($data['nik']),
                'nik_bapak'    => e($data['nik_bapak']),
                'nama_bapak'   => e($data['nama_bapak']),
                'status_bapak' => e($data['status_bapak']),
                'alamat_bapak' => e($data['alamat_bapak']),
                'nik_ibu'      => e($data['nik_ibu']),
                'nama_ibu'     => e($data['nama_ibu']),
                'status_ibu'   => e($data['status_ibu']),
                'alamat_ibu'   => e($data['alamat_ibu']),
                'status'       => (empty($data['status'])) ? '0' : e($data['status']),
            ]);

            // flush cache with tags
            $this->cache->flush(Ortu::$tags);

            return $result;

        } catch (\Exception $e) {
            // store errors to log
            Log::error('class : ' . OrtuRepository::class . ' method : create | ' . $e);

            return $this->createError();
        }

    }

    /**
     * @param       $id
     * @param array $data
     *
     * @return \Symfony\Component\HttpFoundation\Response
     */
    public function update($id, array $data)
    {
        try {
            $result = parent::update($id, [
                'nik'          => e($data['nik']),
                'nik_bapak'    => e($data['nik_bapak']),
                'nama_bapak'   => e($data['nama_bapak']),
                'status_bapak' => e($data['status_bapak']),
                'alamat_bapak' => e($data['alamat_bapak']),
                'nik_ibu'      => e($data['nik_ibu']),
                'nama_ibu'     => e($data['nama_ibu']),
                'status_ibu'   => e($data['status_ibu']),
                'alamat_ibu'   => e($data['alamat_ibu']),
                'status'       => (empty($data['status'])) ? '0' : e($data['status']),
            ]);

            // flush cache with tags
            $this->cache->flush(Ortu::$tags);

            return $result;

        } catch (\Exception $e) {
            // store errors to log
            Log::error('class : ' . OrtuRepository::class . ' method : update | ' . $e);

            return $this->createError();
        }
    }

    /**
     * @param $id
     *
     * @return \Symfony\Component\HttpFoundation\Response
     */
    public function delete($id)
    {
        try {
            $result = parent::delete($id);

            // flush cache with tags
            $this->cache->flush(Ortu::$tags);

            return $result;

        } catch (\Exception $e) {
            // store errors to log
            Log::error('class : ' . OrtuRepository::class . ' method : delete | ' . $e);

            return $this->createError();
        }
    }

    /**
     * @param int    $limit
     * @param int    $page
     * @param array  $column
     * @param string $field
     * @param string $search
     *
     * @return \Illuminate\Pagination\Paginator
     */
    public function getByPage($limit = 10, $page = 1, array $column = ['*'], $field, $search = '')
    {
        // set key
        $key = 'ortu-get-by-page-' . $page . $limit . $search;

        // has section and key
        if ($this->cache->has(Ortu::$tags, $key)) {
            return $this->cache->get(Ortu::$tags, $key);
        }

        // query to sql
        $result = parent::getByPageOrderBy($limit, $page, $column, 'nik', $search, 'created_at');

        // store to cache
        $this->cache->put(Ortu::$tags, $key, $result, 10);

        return $result;
    }

}
<file_sep><?php

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateTableBiometric extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('biometric', function (Blueprint $table) {
            $table->engine = 'InnoDB';
            $table->increments('id');
            $table->string('nik', 16)->unique();
            $table->string('foto');
            $table->string('tanda tangan');
            $table->text('iris_mata_kanan')->nullable();
            $table->text('iris_mata_kiri')->nullable();
            $table->text('kelingking_kiri')->nullable();
            $table->text('manis_kiri')->nullable();
            $table->text('tengah_kiri')->nullable();
            $table->text('telunjuk_kiri')->nullable();
            $table->text('jempol_kiri')->nullable();
            $table->text('kelingking_kanan')->nullable();
            $table->text('manis_kanan')->nullable();
            $table->text('tengah_kanan')->nullable();
            $table->text('telunjuk_kanan')->nullable();
            $table->text('jempol_kanan')->nullable();
            $table->boolean('status')->default(0);
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::drop('biometric');
    }
}
<file_sep><?php

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateTableDokumen extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('dokumen', function (Blueprint $table) {
            $table->engine = 'InnoDB';
            $table->increments('id');
            $table->string('nik', 16)->unique();
            $table->string('jenis_dokumen', 1);
            $table->string('nomor_dokumen', 32);
            $table->string('tempat_terbit', 58);
            $table->string('tanggal_terbit', 16);
            $table->string('nomor_seri', 58);
            $table->string('pejabat', 200);
            $table->boolean('status')->default(0);
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::drop('dokumen');
    }
}
<file_sep><?php

use Illuminate\Database\Seeder;

class KecamatanSeeder extends Seeder

{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        DB::table('kecamatan')->truncate();
        DB::table('kecamatan')->insert([
            ['id' => 1, 'kabupaten_id' => '73', 'kode_kecamatan' => '01', 'kecamatan' => 'Blimbing', 'pbb_kec_kode' => '', 'arsip_kec_kode' => '', 'kodepos_kec_kode' => '', 'ramil_kec_kode' => ''],
            ['id' => 2, 'kabupaten_id' => '73', 'kode_kecamatan' => '02', 'kecamatan' => 'Klojen', 'pbb_kec_kode' => '', 'arsip_kec_kode' => '', 'kodepos_kec_kode' => '', 'ramil_kec_kode' => ''],
            ['id' => 3, 'kabupaten_id' => '73', 'kode_kecamatan' => '03', 'kecamatan' => 'Kedungkandang', 'pbb_kec_kode' => '', 'arsip_kec_kode' => '', 'kodepos_kec_kode' => '', 'ramil_kec_kode' => ''],
            ['id' => 4, 'kabupaten_id' => '73', 'kode_kecamatan' => '04', 'kecamatan' => 'Sukun', 'pbb_kec_kode' => '', 'arsip_kec_kode' => '', 'kodepos_kec_kode' => '', 'ramil_kec_kode' => ''],
            ['id' => 5, 'kabupaten_id' => '73', 'kode_kecamatan' => '05', 'kecamatan' => 'Lowokwaru', 'pbb_kec_kode' => '', 'arsip_kec_kode' => '', 'kodepos_kec_kode' => '', 'ramil_kec_kode' => ''],
        ]);
    }
}
<file_sep><?php namespace App\Http\Requests\Kependudukan;

use App\Http\Requests\Request;
use Illuminate\Contracts\Validation\Validator;

class PribadiFormRequest extends Request
{
    /**
     * @var array
     */
    protected $attrs = [
        'keluarga_id'     => 'Keluarga',
        'nik'             => 'NIK',
        'title_depan'     => 'Title Depan',
        'title_belakang'  => 'Title Belakang',
        'nama'            => 'Nama',
        'kelamin'         => 'Jenis Kelamin',
        'tempat_lahir'    => 'Tempat Lahir',
        'tanggal_lahir'   => 'Tanggal Lahir',
        'golongan_darah'  => 'Golongan Darah',
        'agama'           => 'Agama',
        'status_kawin'    => 'Status Kawin',
        'status_keluarga' => 'Status Keluarga',
        'pendidikan'      => 'Pendidikan',
        'pekerjaan'       => 'Pekerjaan',
    ];

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'keluarga_id'     => 'required|max:50',
            'nik'             => 'required|max:25|unique:pribadi,nik',
            'nama'            => 'required|max:50',
            'kelamin'         => 'required|max:10',
            'tempat_lahir'    => 'required|max:35',
            'tanggal_lahir'   => 'required|max:10',
            'golongan_darah'  => 'max:2',
            'agama'           => 'required|max:12',
            'status_kawin'    => 'required|max:12',
            'status_keluarga' => 'required|max:50',
            'title_depan'     => 'max:20',
            'title_belakang'  => 'max:20',
            'pendidikan'      => 'max:35',
            'pekerjaan'       => 'max:35',
        ];
    }

    /**
     * @param $validator
     *
     * @return mixed
     */
    public function validator($validator)
    {
        return $validator->make($this->all(), $this->container->call([$this, 'rules']), $this->messages(), $this->attrs);
    }

    /**
     * @param Validator $validator
     *
     * @return array
     */
    protected function formatErrors(Validator $validator)
    {
        $message = $validator->errors();

        return [
            'success'    => false,
            'validation' => [
                'keluarga_id'     => $message->first('keluarga_id'),
                'nik'             => $message->first('nik'),
                'nama'            => $message->first('nama'),
                'kelamin'         => $message->first('kelamin'),
                'tempat_lahir'    => $message->first('tempat_lahir'),
                'tanggal_lahir'   => $message->first('tanggal_lahir'),
                'golongan_darah'  => $message->first('golongan_darah'),
                'agama'           => $message->first('agama'),
                'status_kawin'    => $message->first('status_kawin'),
                'status_keluarga' => $message->first('status_keluarga'),
                'title_depan'     => $message->first('title_depan'),
                'title_belakang'  => $message->first('title_belakang'),
                'pendidikan'      => $message->first('pendidikan'),
                'pekerjaan'       => $message->first('pekerjaan'),
            ]
        ];
    }
}
<file_sep><?php

use Illuminate\Database\Seeder;

class KabkotaSeeder extends Seeder

{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        DB::table('kabkot')->truncate();
        DB::table('kabkot')->insert([
            ['id' => 1, 'provinsi_id' => '35', 'kode_kabupaten' => '73', 'kabupaten' => 'Malang', 'is_status' => '2', 'pbb_kabukot_kode' => '', 'arsip_kabukot_kode' => '', 'kodepos_kabukot_kode' => '', 'ramil_kabukot_kode' => ''],
        ]);
    }
}
<file_sep><?php namespace App\Domain\Repositories\Kependudukan;

use App\Domain\Contracts\Cacheable;
use App\Domain\Contracts\Crudable;
use App\Domain\Contracts\Paginable;
use App\Domain\Entities\Kependudukan\PribadiRincian;
use App\Domain\Repositories\AbstractRepository;
use Illuminate\Support\Facades\Log;

class PribadiRincianRepository extends AbstractRepository implements Crudable, Paginable
{
    /**
     * @var Cacheable
     */
    protected $cache;

    /**
     * @param PribadiRincian $pribadi
     * @param Cacheable      $cache
     */
    public function __construct(PribadiRincian $pribadi, Cacheable $cache)
    {
        $this->model = $pribadi;
        $this->cache = $cache;
    }

    /**
     * @param int   $id
     * @param array $columns
     *
     * @return \Illuminate\Database\Eloquent\Model
     */
    public function find($id, array $columns = ['*'])
    {
        // set key
        $key = 'pribadi-rincian-find-' . $id;

        // has section and key
        if ($this->cache->has(PribadiRincian::$tags, $key)) {
            return $this->cache->get(PribadiRincian::$tags, $key);
        }

        // query to sql
        $result = parent::find($id, $columns);

        // store to cache
        $this->cache->put(PribadiRincian::$tags, $key, $result, 10);

        return $result;
    }

    /**
     * @param array $data
     *
     * @return \Symfony\Component\HttpFoundation\Response
     */
    public function create(array $data)
    {
        try {

            // execute sql insert
            $result = parent::create([
                'nik'            => e($data['nik']),
                'kelainan_fisik' => (empty($data['kelainan_fisik'])) ? null : e($data['kelainan_fisik']),
                'cacat_fisik'    => (empty($data['cacat_fisik'])) ? null : e($data['cacat_fisik']),
                'warga_negara'   => e($data['warga_negara']),
                'website'        => (empty($data['website'])) ? null : e($data['website']),
                'email'          => (empty($data['email'])) ? null : e($data['email']),
                'telp'           => (empty($data['telp'])) ? null : e($data['telp']),
                'status'         => (empty($data['status'])) ? '0' : e($data['status']),
            ]);

            // flush cache with tags
            $this->cache->flush(PribadiRincian::$tags);

            return $result;

        } catch (\Exception $e) {
            // store errors to log
            Log::error('class : ' . PribadiRincianRepository::class . ' method : create | ' . $e);

            return $this->createError();
        }

    }

    /**
     * @param       $id
     * @param array $data
     *
     * @return \Symfony\Component\HttpFoundation\Response
     */
    public function update($id, array $data)
    {
        try {
            $result = parent::update($id, [
                'nik'            => e($data['nik']),
                'kelainan_fisik' => (empty($data['kelainan_fisik'])) ? null : e($data['kelainan_fisik']),
                'cacat_fisik'    => (empty($data['cacat_fisik'])) ? null : e($data['cacat_fisik']),
                'warga_negara'   => e($data['warga_negara']),
                'website'        => (empty($data['website'])) ? null : e($data['website']),
                'email'          => (empty($data['email'])) ? null : e($data['email']),
                'telp'           => (empty($data['telp'])) ? null : e($data['telp']),
                'status'         => (empty($data['status'])) ? '0' : e($data['status']),
            ]);

            // flush cache with tags
            $this->cache->flush(PribadiRincian::$tags);

            return $result;

        } catch (\Exception $e) {
            // store errors to log
            Log::error('class : ' . PribadiRincianRepository::class . ' method : update | ' . $e);

            return $this->createError();
        }
    }

    /**
     * @param $id
     *
     * @return \Symfony\Component\HttpFoundation\Response
     */
    public function delete($id)
    {
        try {
            $result = parent::delete($id);

            // flush cache with tags
            $this->cache->flush(PribadiRincian::$tags);

            return $result;

        } catch (\Exception $e) {
            // store errors to log
            Log::error('class : ' . PribadiRincianRepository::class . ' method : delete | ' . $e);

            return $this->createError();
        }
    }

    /**
     * @param int    $limit
     * @param int    $page
     * @param array  $column
     * @param string $field
     * @param string $search
     *
     * @return \Illuminate\Pagination\Paginator
     */
    public function getByPage($limit = 10, $page = 1, array $column = ['*'], $field, $search = '')
    {
        // set key
        $key = 'pribadi-rincian-get-by-page-' . $page . $limit . $search;

        // has section and key
        if ($this->cache->has(PribadiRincian::$tags, $key)) {
            return $this->cache->get(PribadiRincian::$tags, $key);
        }

        // query to sql
        $result = parent::getByPageOrderBy($limit, $page, $column, 'nik', $search, 'created_at');

        // store to cache
        $this->cache->put(PribadiRincian::$tags, $key, $result, 10);

        return $result;
    }

}
<file_sep><?php

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateTableKecamatan extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('kecamatan', function (Blueprint $table) {
            $table->engine = 'InnoDB';
            $table->increments('id');
            $table->integer('kabupaten_id');
            $table->string('kode_kecamatan', 2);
            $table->string('kecamatan', 200);
            $table->string('status');
            $table->integer('pbb_kec_kode');
            $table->integer('arsip_kec_kode');
            $table->integer('kodepos_kec_kode');
            $table->integer('ramil_kec_kode');
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::drop('kecamatan');
    }
}
<file_sep>## Aplikasi Kependudukan untuk Hackathon Merdeka 2.0
<file_sep><?php namespace App\Http\Requests\Kependudukan;

use App\Http\Requests\Request;
use Illuminate\Contracts\Validation\Validator;

class KeluargaFormRequest extends Request
{

    /**
     * @var array
     */
    protected $attrs = [
        'nik_kk'  => 'NIK KK',
        'nama_kk' => 'Nama KK',
        'alamat'  => 'Alamat',
        'rt'      => 'RT',
        'rw'      => 'RW',
        'dusun'   => 'Dusun',
        'telepon' => 'Telepon',
    ];

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'nik_kk'  => 'required|max:16|unique:keluarga,nik_kk',
            'nama_kk' => 'required|max:60',
            'alamat'  => 'required|max:225',
            'rt'      => 'required|max:3',
            'rw'      => 'required|max:3',
            'dusun'   => 'required|max:50',
            'telepon' => 'max:15',
        ];
    }

    /**
     * @param $validator
     *
     * @return mixed
     */
    public function validator($validator)
    {
        return $validator->make($this->all(), $this->container->call([$this, 'rules']), $this->messages(), $this->attrs);
    }

    /**
     * @param Validator $validator
     *
     * @return array
     */
    protected function formatErrors(Validator $validator)
    {
        $message = $validator->errors();

        return [
            'success'    => false,
            'validation' => [
                'nik_kk'  => $message->first('nik_kk'),
                'nama_kk' => $message->first('nama_kk'),
                'alamat'  => $message->first('alamat'),
                'rt'      => $message->first('rt'),
                'rw'      => $message->first('rw'),
                'dusun'   => $message->first('dusun'),
                'telepon' => $message->first('telepon'),
            ]
        ];
    }
}
