<?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use App\Http\Requests\MassDestroyReferensipkapkRequest;
use App\Http\Requests\StoreReferensipkapkRequest;
use App\Http\Requests\UpdateReferensipkapkRequest;
use App\Referensi;
use App\Referensipkapk;

class ReferensipkapkController extends Controller
{
    public function index()
    {
        abort_unless(\Gate::allows('referensipkapk_access'), 403);

        $referensipkapks = Referensipkapk::all();

        return view('admin.referensipkapks.index', compact('referensipkapks'));
    }

    public function create()
    {
        abort_unless(\Gate::allows('referensipkapk_create'), 403);

        $pangkat_gols = Referensi::all()->pluck('pangkat_gol', 'id')->prepend(trans('global.pleaseSelect'), '');

        return view('admin.referensipkapks.create', compact('pangkat_gols'));
    }

    public function store(StoreReferensipkapkRequest $request)
    {
        abort_unless(\Gate::allows('referensipkapk_create'), 403);

        $referensipkapk = Referensipkapk::create($request->all());

        return redirect()->route('admin.referensipkapks.index');
    }

    public function edit(Referensipkapk $referensipkapk)
    {
        abort_unless(\Gate::allows('referensipkapk_edit'), 403);

        $pangkat_gols = Referensi::all()->pluck('pangkat_gol', 'id')->prepend(trans('global.pleaseSelect'), '');

        $referensipkapk->load('pangkat_gol');

        return view('admin.referensipkapks.edit', compact('pangkat_gols', 'referensipkapk'));
    }

    public function update(UpdateReferensipkapkRequest $request, Referensipkapk $referensipkapk)
    {
        abort_unless(\Gate::allows('referensipkapk_edit'), 403);

        $referensipkapk->update($request->all());

        return redirect()->route('admin.referensipkapks.index');
    }

    public function show(Referensipkapk $referensipkapk)
    {
        abort_unless(\Gate::allows('referensipkapk_show'), 403);

        $referensipkapk->load('pangkat_gol');

        return view('admin.referensipkapks.show', compact('referensipkapk'));
    }

    public function destroy(Referensipkapk $referensipkapk)
    {
        abort_unless(\Gate::allows('referensipkapk_delete'), 403);

        $referensipkapk->delete();

        return back();
    }

    public function massDestroy(MassDestroyReferensipkapkRequest $request)
    {
        Referensipkapk::whereIn('id', request('ids'))->delete();

        return response(null, 204);
    }
}
