';
})
->make();
}
/**
* Create a Category.
*
* @param type Category $category
*
* @return type view
*/
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 */
try {
return view('themes.default1.agent.kb.category.create', compact('category'));
} catch (Exception $e) {
return redirect()->back()->with('fails', $e->getMessage());
}
}
/**
* To store the selected category.
*
* @param type Category $category
* @param type CategoryRequest $request
*
* @return type Redirect
*/
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;
// send success message to index page
try {
$category->fill($request->except('slug'))->save();
return Redirect::back()->with('success', Lang::get('lang.category_inserted_successfully'));
} catch (Exception $e) {
return Redirect::back()->with('fails', Lang::get('lang.category_not_inserted') . '
' . $e->getMessage() . '
');
}
}
/**
* Show the form for editing the specified category.
*
* @param type $slug
* @param type Category $category
*
* @return type view
*/
public function edit($slug) {
// fetch the 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 Category in storage.
*
* @param type $slug
* @param type Category $category
* @param type CategoryUpdate $request
*
* @return type redirect
*/
public function update($slug, 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 */
//redirct to index page with success message
try {
$category->fill($request->all())->save();
$category->slug = $slug;
$category->save();
return redirect('category')->with('success', Lang::get('lang.category_updated_successfully'));
} catch (Exception $e) {
//redirect to index with fails message
return redirect('category')->with('fails', Lang::get('lang.category_not_updated') . '
' . $e->getMessage() . '
');
}
}
/**
* Remove the specified category from storage.
*
* @param type $id
* @param type Category $category
* @param type Relationship $relation
*
* @return type Redirect
*/
public function destroy($id, Category $category, Relationship $relation) {
$relation = $relation->where('category_id', $id)->first();
if ($relation != null) {
return Redirect::back()->with('fails', Lang::get('lang.category_not_deleted'));
} else {
/* delete the category selected, id == $id */
$category = $category->whereId($id)->first();
// redirect to index with success message
try {
$category->delete();
return Redirect::back()->with('success', Lang::get('lang.category_deleted_successfully'));
} catch (Exception $e) {
return Redirect::back()->with('fails', Lang::get('lang.category_not_deleted') . '