update v1.0.5
This commit is contained in:
@@ -1,33 +1,47 @@
|
||||
<?php namespace App\Http\Controllers\Agent\kb;
|
||||
|
||||
// Controllers
|
||||
use App\Http\Controllers\client\kb\UserController;
|
||||
use App\Http\Controllers\admin\kb\ArticleController;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Controllers\Agent\kb\SettingsController;
|
||||
use App\Http\Controllers\Agent\helpdesk\TicketController;
|
||||
|
||||
// Requests
|
||||
use App\Http\Requests\kb\CategoryRequest;
|
||||
use App\Http\Requests\kb\CategoryUpdate;
|
||||
use App\Http\Controllers\Agent\helpdesk\TicketController;
|
||||
|
||||
// Model
|
||||
use App\Model\kb\Category;
|
||||
use App\Model\kb\Relationship;
|
||||
|
||||
// Classes
|
||||
use Datatable;
|
||||
use Redirect;
|
||||
use Exception;
|
||||
|
||||
/**
|
||||
* CategoryController
|
||||
* This controller is used to CRUD category
|
||||
*
|
||||
* @package Controllers
|
||||
* @subpackage Controller
|
||||
* @author Ladybird <info@ladybirdweb.com>
|
||||
* @package Controllers
|
||||
* @subpackage Controller
|
||||
* @author Ladybird <info@ladybirdweb.com>
|
||||
*/
|
||||
|
||||
class CategoryController extends Controller {
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return Response
|
||||
* Create a new controller instance.
|
||||
* constructor to check
|
||||
* 1. authentication
|
||||
* 2. user roles
|
||||
* 3. roles must be agent
|
||||
* @return void
|
||||
*/
|
||||
public function __construct() {
|
||||
// checking authentication
|
||||
$this->middleware('auth');
|
||||
// checking roles
|
||||
$this->middleware('roles');
|
||||
SettingsController::language();
|
||||
}
|
||||
@@ -38,48 +52,56 @@ class CategoryController extends Controller {
|
||||
* @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');
|
||||
try{
|
||||
return view('themes.default1.agent.kb.category.index');
|
||||
} catch (Exception $e) {
|
||||
return redirect()->back()->with('fails', $e->errorInfo[2]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* fetching category list in chumper datatables
|
||||
* @return type chumper datatable
|
||||
*/
|
||||
public function getData() {
|
||||
|
||||
//return 'kfjhje';
|
||||
|
||||
/* fetching chumper datatables */
|
||||
return Datatable::collection(Category::All())
|
||||
/* search column name */
|
||||
->searchColumns('name')
|
||||
/* order column name and description */
|
||||
->orderColumns('name', 'description')
|
||||
/* add column name */
|
||||
->addColumn('name', function ($model) {
|
||||
return $model->name;
|
||||
})
|
||||
|
||||
/* add column Created */
|
||||
->addColumn('Created', function ($model) {
|
||||
|
||||
$t = $model->created_at;
|
||||
return TicketController::usertimezone($t);
|
||||
})
|
||||
/* add column Actions */
|
||||
/* there are action buttons and modal popup to delete a data column */
|
||||
->addColumn('Actions', function ($model) {
|
||||
//return '<a href=category/delete/' . $model->id . ' class="btn btn-danger btn-flat">Delete</a> <a href=category/' . $model->id . '/edit class="btn btn-warning btn-flat">Edit</a> <a href=article-list class="btn btn-warning btn-flat">View</a>';
|
||||
return '<span data-toggle="modal" data-target="#deletecategory' . $model->slug . '"><a href="#" ><button class="btn btn-danger btn-xs"></a>'. \Lang::get("lang.delete") .'</button></span> <a href=category/' . $model->id . '/edit class="btn btn-warning btn-xs">'. \Lang::get("lang.edit") .'</a> <a href=article-list class="btn btn-primary btn-xs">'. \Lang::get("lang.view") .'</a>
|
||||
<div class="modal fade" id="deletecategory' . $model->slug . '">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
|
||||
<h4 class="modal-title">Are You Sure ?</h4>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
'.$model->name.'
|
||||
</div>
|
||||
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-default pull-left" data-dismiss="modal" id="dismis2">Close</button>
|
||||
<a href="category/delete/' . $model->id . '"><button class="btn btn-danger">delete</button></a>
|
||||
</div>
|
||||
</div><!-- /.modal-content -->
|
||||
</div><!-- /.modal-dialog -->
|
||||
</div>';
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
|
||||
<h4 class="modal-title">Are You Sure ?</h4>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
'.$model->name.'
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-default pull-left" data-dismiss="modal" id="dismis2">Close</button>
|
||||
<a href="category/delete/' . $model->id . '"><button class="btn btn-danger">delete</button></a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>';
|
||||
})
|
||||
->make();
|
||||
|
||||
@@ -88,71 +110,62 @@ class CategoryController extends Controller {
|
||||
/**
|
||||
* Create a Category
|
||||
* @param type Category $category
|
||||
* @return Response
|
||||
* @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*/
|
||||
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');
|
||||
try {
|
||||
return view('themes.default1.agent.kb.category.create', compact('category'));
|
||||
} catch(Exception $e) {
|
||||
return redirect()->back()->with('fails',$e->errorInfo[2]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @param int $id
|
||||
* @return Response
|
||||
* To store the selected category
|
||||
* @param type Category $category
|
||||
* @param type CategoryRequest $request
|
||||
* @return type Redirect
|
||||
*/
|
||||
public function show($id) {
|
||||
//
|
||||
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', 'Category Inserted Successfully');
|
||||
} catch(Exception $e) {
|
||||
return Redirect::back()->with('fails', 'Category Not Inserted'.'<li>'.$e->errorInfo[2].'</li>');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*
|
||||
* @param int $id
|
||||
* @return Response
|
||||
* Show the form for editing the specified category.
|
||||
* @param type $slug
|
||||
* @param type Category $category
|
||||
* @return type view
|
||||
*/
|
||||
public function edit($slug, Category $category) {
|
||||
|
||||
// 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 resource in storage.
|
||||
*
|
||||
* @param int $id
|
||||
* @return Response
|
||||
* Update the specified Category in storage.
|
||||
* @param type $slug
|
||||
* @param type Category $category
|
||||
* @param type CategoryUpdate $request
|
||||
* @return type redirect
|
||||
*/
|
||||
public function update($slug, Category $category, CategoryUpdate $request) {
|
||||
|
||||
@@ -163,42 +176,41 @@ class CategoryController extends Controller {
|
||||
// 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
|
||||
{
|
||||
//redirct to index page with success message
|
||||
try{
|
||||
$category->fill($request->all())->save();
|
||||
$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');
|
||||
return redirect('category')->with('success', 'Category Updated Successfully');
|
||||
} catch(Exception $e) {
|
||||
//redirect to index with fails message
|
||||
return redirect('category')->with('fails', 'Category Not Updated'.'<li>'.$e->errorInfo[2].'</li>');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param int $id
|
||||
* @return Response
|
||||
* 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();
|
||||
// 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
|
||||
{
|
||||
// redirect to index with success message
|
||||
try{
|
||||
$category->delete();
|
||||
return Redirect::back()->with('success', 'Category Deleted Successfully');
|
||||
} else //redirect to index page fails message
|
||||
{
|
||||
return Redirect::back()->with('fails', 'Category Not Deleted');
|
||||
}
|
||||
|
||||
} catch(Exception $e){
|
||||
return Redirect::back()->with('fails', 'Category Not Deleted'.'<li>'.$e->errorInfo[2].'</li>');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user