*/ class CategoryController extends Controller { /** * Display a listing of the resource. * * @return Response */ public function __construct() { $this->middleware('auth'); $this->middleware('roles'); SettingsController::language(); } /** * Indexing all Category * @param type Category $category * @return Response */ public function index() { /* get the view of index of the catogorys with all attributes of category model */ return view('themes.default1.agent.kb.category.index'); } public function getData() { //return 'kfjhje'; return Datatable::collection(Category::All()) ->searchColumns('name') ->orderColumns('name', 'description') ->addColumn('name', function ($model) { return $model->name; }) ->addColumn('Created', function ($model) { $t = $model->created_at; return TicketController::usertimezone($t); }) ->addColumn('Actions', function ($model) { //return 'id . ' class="btn btn-danger btn-flat">Delete id . '/edit class="btn btn-warning btn-flat">Edit View'; return ' id . '/edit class="btn btn-warning btn-xs">'. \Lang::get("lang.edit") .' '. \Lang::get("lang.view") .' '; }) ->make(); } /** * Create a Category * @param type Category $category * @return Response */ public function create(Category $category) { /* Get the all attributes in the category model */ $category = $category->get(); /* get the view page to create new category with all attributes of category model*/ return view('themes.default1.agent.kb.category.create', compact('category')); } /** * Store a newly created resource in storage. * * @return Response */ public function store(Category $category, CategoryRequest $request) { /* Get the whole request from the form and insert into table via model */ $sl = $request->input('slug'); $slug = str_slug($sl, "-"); $category->slug = $slug; //$category->save(); if ($category->fill($request->except('slug'))->save()) //True: send success message to index page { return Redirect::back()->with('success', 'Category Inserted Successfully'); } else //send fail to index page { return Redirect::back()->with('fails', 'Category Not Inserted'); } } /** * Display the specified resource. * * @param int $id * @return Response */ public function show($id) { // } /** * Show the form for editing the specified resource. * * @param int $id * @return Response */ public function edit($slug, Category $category) { $cid = $category->where('id', $slug)->first(); $id = $cid->id; /* get the atributes of the category model whose id == $id */ $category = $category->whereId($id)->first(); /* get the Edit page the selected category via id */ return view('themes.default1.agent.kb.category.edit', compact('category')); } /** * Update the specified resource in storage. * * @param int $id * @return Response */ public function update($slug, Category $category, CategoryUpdate $request) { /* Edit the selected category via id */ $category = $category->where('id', $slug)->first(); $sl = $request->input('slug'); $slug = str_slug($sl, "-"); // dd($slug); $category->slug = $slug; /* update the values at the table via model according with the request */ if ($category->fill($request->all())->save()) //True: redirct to index page with success message { $category->slug = $slug; $category->save(); return redirect('category')->with('success', 'Category Updated Successfully'); } else //redirect to index with fails message { return redirect('category')->with('fails', 'Category Not Updated'); } } /** * Remove the specified resource from storage. * * @param int $id * @return Response */ public function destroy($id, Category $category, Relationship $relation) { $relation = $relation->where('category_id', $id)->first(); // dd($relation); if($relation != null){ return Redirect::back()->with('fails', 'Category Not Deleted'); } else { /* delete the category selected, id == $id */ $category = $category->whereId($id)->first(); if ($category->delete()) //True: redirect to index with success message { return Redirect::back()->with('success', 'Category Deleted Successfully'); } else //redirect to index page fails message { return Redirect::back()->with('fails', 'Category Not Deleted'); } } } }