<?php

namespace App\Http\Controllers\Admin;

use App\Split;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class SplitController extends Controller
{
    public function __construct()
    {
        if ( alreadyInstalled() ) {
            $this->middleware('auth');
        }
    }

    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        $splits = Split::paginate();

        return view('splits.index', compact('splits'));
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        return view('splits.create');
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        Split::create($request->except('_token'));

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

    /**
     * Show the form for editing the specified resource.
     *
     * @param  \App\Split  $split
     * @return \Illuminate\Http\Response
     */
    public function edit(Split $split)
    {
        return view('splits.edit', compact('split'));
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \App\Split  $split
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, Split $split)
    {
        $split->touch();
        $split->update($request->except('_token'));

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

    /**
     * Remove the specified resource from storage.
     *
     * @param  \App\Split  $split
     * @return \Illuminate\Http\Response
     */
    public function destroy(Split $split)
    {
        $split->delete();

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