<?php

namespace _namespace_controller_;

use Quarx;
use CryptoService;
use Illuminate\Http\Request;
use _app_namespace_Http\Controllers\Controller;
use Quarx\Modules\_ucCamel_casePlural_\Services\_camel_case_Service;
use Quarx\Modules\_ucCamel_casePlural_\Requests\_camel_case_Request;

class _ucCamel_casePlural_Controller extends Controller
{
    public function __construct(_camel_case_Service $_lower_case_Service)
    {
        $this->service = $_lower_case_Service;
    }

    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index(Request $request)
    {
        $_lower_casePlural_ = $this->service->paginated();
        return view('_lower_casePlural_::_lower_casePlural_.index')
            ->with('pagination', $_lower_casePlural_->render())
            ->with('_lower_casePlural_', $_lower_casePlural_);
    }

    /**
     * Display a listing of the resource searched.
     *
     * @return \Illuminate\Http\Response
     */
    public function search(Request $request)
    {
        $_lower_casePlural_ = $this->service->search($request->search);
        return view('_lower_casePlural_::_lower_casePlural_.index')
            ->with('term', $request->search)
            ->with('pagination', $_lower_casePlural_->render())
            ->with('_lower_casePlural_', $_lower_casePlural_);
    }

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

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

        if ($result) {
            Quarx::notification('Successfully created', 'success');
            return redirect('quarx/_lower_casePlural_/'.$result->id.'/edit');
        }

        Quarx::notification('Failed to create', 'warning');
        return redirect('quarx/_lower_casePlural_');
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        $_lower_case_ = $this->service->find($id);
        return view('_lower_casePlural_::_lower_casePlural_.show')->with('_lower_case_', $_lower_case_);
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        $_lower_case_ = $this->service->find($id);
        return view('_lower_casePlural_::_lower_casePlural_.edit')->with('_lower_case_', $_lower_case_);
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\_camel_case_Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(_camel_case_Request $request, $id)
    {
        $result = $this->service->update($id, $request->except(['_token', '_method']));

        if ($result) {
            Quarx::notification('Successfully updated', 'success');
            return back();
        }

        Quarx::notification('Failed to update', 'warning');
        return back();
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        $result = $this->service->destroy($id);

        if ($result) {
            Quarx::notification('Successfully deleted', 'success');
            return redirect('quarx/_lower_casePlural_');
        }

        Quarx::notification('Failed to delete', 'warning');
        return redirect('quarx/_lower_casePlural_');
    }
}
