<?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use App\Http\Requests\MassDestroyReferensiRequest;
use App\Http\Requests\StoreReferensiRequest;
use App\Http\Requests\UpdateReferensiRequest;
use App\Referensi;

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

        $referensis = Referensi::all();

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

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

        return view('admin.referensis.create');
    }

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

        $referensi = Referensi::create($request->all());

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

    public function edit(Referensi $referensi)
    {
        abort_unless(\Gate::allows('referensi_edit'), 403);

        return view('admin.referensis.edit', compact('referensi'));
    }

    public function update(UpdateReferensiRequest $request, Referensi $referensi)
    {
        abort_unless(\Gate::allows('referensi_edit'), 403);

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

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

    public function show(Referensi $referensi)
    {
        abort_unless(\Gate::allows('referensi_show'), 403);

        return view('admin.referensis.show', compact('referensi'));
    }

    public function destroy(Referensi $referensi)
    {
        abort_unless(\Gate::allows('referensi_delete'), 403);

        $referensi->delete();

        return back();
    }

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

        return response(null, 204);
    }
}
