-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Xety
committed
Mar 12, 2018
1 parent
305712e
commit 9e3074f
Showing
23 changed files
with
741 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
138 changes: 138 additions & 0 deletions
138
app/Http/Controllers/Admin/Discuss/CategoryController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
<?php | ||
namespace Xetaravel\Http\Controllers\Admin\Discuss; | ||
|
||
use Illuminate\Http\RedirectResponse; | ||
use Illuminate\Http\Request; | ||
use Illuminate\View\View; | ||
use Xetaravel\Http\Controllers\Admin\Controller; | ||
use Xetaravel\Models\DiscussCategory; | ||
use Xetaravel\Models\Repositories\DiscussCategoryRepository; | ||
use Xetaravel\Models\Validators\DiscussCategoryValidator; | ||
|
||
class CategoryController extends Controller | ||
{ | ||
/** | ||
* Constructor. | ||
*/ | ||
public function __construct() | ||
{ | ||
parent::__construct(); | ||
|
||
$this->breadcrumbs->addCrumb('Discuss', route('admin.discuss.category.index')); | ||
} | ||
|
||
/** | ||
* Show all categories. | ||
* | ||
* @return \Illuminate\View\View | ||
*/ | ||
public function index(): View | ||
{ | ||
$categories = DiscussCategory::paginate(config('xetaravel.pagination.discuss.conversation_per_page')); | ||
|
||
$this->breadcrumbs->addCrumb('Manage Categories', route('admin.discuss.category.index')); | ||
|
||
return view( | ||
'Admin::Discuss.category.index', | ||
['categories' => $categories, 'breadcrumbs' => $this->breadcrumbs] | ||
); | ||
} | ||
|
||
/** | ||
* Show the caterory create form. | ||
* | ||
* @return \Illuminate\View\View | ||
*/ | ||
public function showCreateForm(): View | ||
{ | ||
$breadcrumbs = $this->breadcrumbs | ||
->addCrumb('Manage Categories', route('admin.discuss.category.index')) | ||
->addCrumb("Create", route('admin.discuss.category.create')); | ||
|
||
return view('Admin::Discuss.category.create', ['breadcrumbs' => $this->breadcrumbs]); | ||
} | ||
|
||
/** | ||
* Handle a category create request for the application. | ||
* | ||
* @param \Illuminate\Http\Request $request | ||
* | ||
* @return \Illuminate\Http\RedirectResponse | ||
*/ | ||
public function create(Request $request): RedirectResponse | ||
{ | ||
DiscussCategoryValidator::create($request->all())->validate(); | ||
DiscussCategoryRepository::create($request->all()); | ||
|
||
return redirect() | ||
->route('admin.discuss.category.index') | ||
->with('success', 'Your category has been created successfully !'); | ||
} | ||
|
||
/** | ||
* Show the category update form. | ||
* | ||
* @param string $slug The slug of the category. | ||
* @param int $id The id of the category. | ||
* | ||
* @return \Illuminate\Http\RedirectResponse|\Illuminate\View\View | ||
*/ | ||
public function showUpdateForm(string $slug, int $id) | ||
{ | ||
$category = DiscussCategory::findOrFail($id); | ||
|
||
$breadcrumbs = $this->breadcrumbs | ||
->addCrumb('Manage Categories', route('admin.discuss.category.index')) | ||
->addCrumb( | ||
"Update : " . e(str_limit($category->title, 30)), | ||
route( | ||
'admin.discuss.category.index', | ||
['slug' => $category->slug, 'id' => $category->id] | ||
) | ||
); | ||
|
||
return view('Admin::Discuss.category.update', compact('category', 'breadcrumbs')); | ||
} | ||
|
||
/** | ||
* Handle an category update request for the application. | ||
* | ||
* @param \Illuminate\Http\Request $request | ||
* @param int $id The id of the category. | ||
* | ||
* @return \Illuminate\Http\RedirectResponse | ||
*/ | ||
public function update(Request $request, int $id): RedirectResponse | ||
{ | ||
$category = DiscussCategory::findOrFail($id); | ||
|
||
DiscussCategoryValidator::update($request->all(), $id)->validate(); | ||
DiscussCategoryRepository::update($request->all(), $category); | ||
|
||
return redirect() | ||
->route('admin.discuss.category.index') | ||
->with('success', 'Your category has been updated successfully !'); | ||
} | ||
|
||
/** | ||
* Handle the delete request for the category. | ||
* | ||
* @param int $id The id of the category to delete. | ||
* | ||
* @return \Illuminate\Http\RedirectResponse | ||
*/ | ||
public function delete(int $id): RedirectResponse | ||
{ | ||
$category = DiscussCategory::findOrFail($id); | ||
|
||
if ($category->delete()) { | ||
return redirect() | ||
->route('admin.discuss.category.index') | ||
->with('success', 'This category has been deleted successfully !'); | ||
} | ||
|
||
return redirect() | ||
->route('admin.discuss.category.index') | ||
->with('danger', 'An error occurred while deleting this category !'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
namespace Xetaravel\Models\Validators; | ||
|
||
use Eloquence\Behaviours\Slug; | ||
use Illuminate\Support\Facades\Validator as FacadeValidator; | ||
use Illuminate\Validation\Rule; | ||
use Illuminate\Validation\Validator; | ||
|
||
class DiscussCategoryValidator | ||
{ | ||
/** | ||
* Get a validator for an incoming create request. | ||
* | ||
* @param array $data The data to validate. | ||
* | ||
* @return \Illuminate\Validation\Validator | ||
*/ | ||
public static function create(array $data): Validator | ||
{ | ||
$rules = [ | ||
'title' => 'required|min:5', | ||
'slug' => 'unique:discuss_categories', | ||
'color' => 'min:7|max:7', | ||
'description' => 'required|min:10' | ||
]; | ||
$data['slug'] = Slug::fromTitle($data['title']); | ||
|
||
return FacadeValidator::make($data, $rules); | ||
} | ||
|
||
/** | ||
* Get a validator for an incoming update request. | ||
* | ||
* @param array $data The data to validate. | ||
* @param int $id The actual category id to ignore the slug rule. | ||
* | ||
* @return \Illuminate\Validation\Validator | ||
*/ | ||
public static function update(array $data, int $id): Validator | ||
{ | ||
$rules = [ | ||
'title' => 'required|min:5', | ||
'slug' => [ | ||
Rule::unique('discuss_categories')->ignore($id) | ||
], | ||
'color' => 'min:7|max:7', | ||
'description' => 'required|min:10' | ||
]; | ||
$data['slug'] = Slug::fromTitle($data['title']); | ||
|
||
return FacadeValidator::make($data, $rules); | ||
} | ||
} |
Oops, something went wrong.