<?php namespace App\Http\Controllers\Webprofile\Backend; use Illuminate\Http\Request; use App\Http\Controllers\Controller; use App\Repositories\Webprofile\CategoryRepository; class CategoryController extends Controller { private $repo; public function __construct(CategoryRepository $repo) { $this->repo = $repo; } /** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ public function index(Request $request) { if ($request->ajax()) { $data = $this->repo->get(); return $this->repo->datatable($data); } return view('webprofile.backend.categories.index')->withTitle(trans('feature.category')); } /** * Show the form for creating a new resource. * * @return \Illuminate\Http\Response */ public function create() { return view('webprofile.backend.categories.create')->withTitle(trans('feature.create_category')); } /** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { $data = $request->except('_token'); array_key_exists('is_active', $data) ? $data['is_active'] = 1 : $data['is_active'] = 0; $this->repo->store($data); return redirect()->route('category.index'); } /** * Display the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function show($id) { // } /** * Show the form for editing the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function edit($id) { $data = $this->repo->findId($id); $data = [ 'data' => $data, ]; return view('webprofile.backend.categories.edit', $data)->withTitle(trans('feature.create_category')); } /** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param int $id * @return \Illuminate\Http\Response */ public function update(Request $request, $id) { $data = $request->except(['_token', 'id']); array_key_exists('is_active', $data) ? $data['is_active'] = 1 : $data['is_active'] = 0; $category = $this->repo->findId($id); $edit = $this->repo->update($data, $category); return redirect()->route('category.index'); } /** * Remove the specified resource from storage. * * @param int $id * @return \Illuminate\Http\Response */ public function destroy($id) { $data = $this->repo->findId($id); $this->repo->destroy($data); return response()->json(['done']); } }