Commit 7456b1f3 authored by Vipul Basapati's avatar Vipul Basapati

Refactored Blog Category Module

parent 09d543ed
......@@ -14,13 +14,13 @@ class BlogCategoryCreated
/**
* @var
*/
public $blogcategories;
public $blogcategory;
/**
* @param $blogcategories
* @param $blogcategory
*/
public function __construct($blogcategories)
public function __construct($blogcategory)
{
$this->blogcategories = $blogcategories;
$this->blogcategory = $blogcategory;
}
}
......@@ -14,13 +14,13 @@ class BlogCategoryDeleted
/**
* @var
*/
public $blogcategories;
public $blogcategory;
/**
* @param $blogcategories
* @param $blogcategory
*/
public function __construct($blogcategories)
public function __construct($blogcategory)
{
$this->blogcategories = $blogcategories;
$this->blogcategory = $blogcategory;
}
}
......@@ -14,13 +14,13 @@ class BlogCategoryUpdated
/**
* @var
*/
public $blogcategories;
public $blogcategory;
/**
* @param $blogcategories
* @param $blogcategory
*/
public function __construct($blogcategories)
public function __construct($blogcategory)
{
$this->blogcategories = $blogcategories;
$this->blogcategory = $blogcategory;
}
}
......@@ -17,21 +17,18 @@ use App\Repositories\Backend\BlogCategories\BlogCategoriesRepository;
*/
class BlogCategoriesController extends Controller
{
/**
* @var BlogCategoriesRepository
*/
protected $blogcategories;
protected $blogcategory;
/**
* @param BlogCategoriesRepository $blogcategories
* @param BlogCategoriesRepository $blogcategory
*/
public function __construct(BlogCategoriesRepository $blogcategories)
public function __construct(BlogCategoriesRepository $blogcategory)
{
$this->blogcategories = $blogcategories;
$this->blogcategory = $blogcategory;
}
/**
* @param ManageBlogCategoriesRequest $request
* @param \App\Http\Requests\Backend\BlogCategories\ManageBlogCategoriesRequest $request
*
* @return mixed
*/
......@@ -41,7 +38,7 @@ class BlogCategoriesController extends Controller
}
/**
* @param CreateBlogCategoriesRequest $request
* @param \App\Http\Requests\Backend\BlogCategories\CreateBlogCategoriesRequest $request
*
* @return mixed
*/
......@@ -51,52 +48,58 @@ class BlogCategoriesController extends Controller
}
/**
* @param StoreBlogCategoriesRequest $request
* @param \App\Http\Requests\Backend\BlogCategories\StoreBlogCategoriesRequest $request
*
* @return mixed
*/
public function store(StoreBlogCategoriesRequest $request)
{
$this->blogcategories->create($request->all());
$this->blogcategory->create($request->all());
return redirect()->route('admin.blogcategories.index')->withFlashSuccess(trans('alerts.backend.blogcategories.created'));
return redirect()
->route('admin.blogcategories.index')
->with('flash_success', trans('alerts.backend.blogcategories.created'));
}
/**
* @param BlogCategory $blogcategory
* @param EditBlogCategoriesRequest $request
* @param \App\Models\BlogCategories\BlogCategory $blogcategory
* @param \App\Http\Requests\Backend\BlogCategories\EditBlogCategoriesRequest $request
*
* @return mixed
*/
public function edit(BlogCategory $blogcategory, EditBlogCategoriesRequest $request)
{
return view('backend.blogcategories.edit')
->withBlogcategory($blogcategory);
->with('blogcategory', $blogcategory);
}
/**
* @param BlogCategory $blogcategory
* @param UpdateBlogCategoriesRequest $request
* @param \App\Models\BlogCategories\BlogCategory $blogcategory
* @param \App\Http\Requests\Backend\BlogCategories\UpdateBlogCategoriesRequest $request
*
* @return mixed
*/
public function update(BlogCategory $blogcategory, UpdateBlogCategoriesRequest $request)
{
$this->blogcategories->update($blogcategory, $request->all());
$this->blogcategory->update($blogcategory, $request->all());
return redirect()->route('admin.blogcategories.index')->withFlashSuccess(trans('alerts.backend.blogcategories.updated'));
return redirect()
->route('admin.blogcategories.index')
->with('flash_success', trans('alerts.backend.blogcategories.updated'));
}
/**
* @param BlogCategory $blogcategory
* @param DeleteBlogCategoriesRequest $request
* @param \App\Models\BlogCategories\BlogCategory $blogcategory
* @param \App\Http\Requests\Backend\BlogCategories\DeleteBlogCategoriesRequest $request
*
* @return mixed
*/
public function destroy(BlogCategory $blogcategory, DeleteBlogCategoriesRequest $request)
{
$this->blogcategories->delete($blogcategory);
$this->blogcategory->delete($blogcategory);
return redirect()->route('admin.blogcategories.index')->withFlashSuccess(trans('alerts.backend.blogcategories.deleted'));
return redirect()
->route('admin.blogcategories.index')
->with('flash_success', trans('alerts.backend.blogcategories.deleted'));
}
}
......@@ -13,43 +13,36 @@ use Yajra\DataTables\Facades\DataTables;
*/
class BlogCategoriesTableController extends Controller
{
/**
* @var BlogCategoriesRepository
*/
protected $blogcategories;
protected $blogcategory;
/**
* @param BlogCategoriesRepository $cmspages
* @param \App\Repositories\Backend\BlogCategories\BlogCategoriesRepository $cmspages
*/
public function __construct(BlogCategoriesRepository $blogcategories)
public function __construct(BlogCategoriesRepository $blogcategory)
{
$this->blogcategories = $blogcategories;
$this->blogcategory = $blogcategory;
}
/**
* @param ManageBlogCategoriesRequest $request
* @param \App\Http\Requests\Backend\BlogCategories\ManageBlogCategoriesRequest $request
*
* @return mixed
*/
public function __invoke(ManageBlogCategoriesRequest $request)
{
return Datatables::of($this->blogcategories->getForDataTable())
return Datatables::of($this->blogcategory->getForDataTable())
->escapeColumns(['name'])
->addColumn('status', function ($blogcategories) {
if ($blogcategories->status) {
return '<span class="label label-success">Active</span>';
}
return '<span class="label label-danger">Inactive</span>';
->addColumn('status', function ($blogcategory) {
return $blogcategory->status_label;
})
->addColumn('created_by', function ($blogcategories) {
return $blogcategories->user_name;
->addColumn('created_by', function ($blogcategory) {
return $blogcategory->user_name;
})
->addColumn('created_at', function ($blogcategories) {
return Carbon::parse($blogcategories->created_at)->toDateString();
->addColumn('created_at', function ($blogcategory) {
return Carbon::parse($blogcategory->created_at)->toDateString();
})
->addColumn('actions', function ($blogcategories) {
return $blogcategories->action_buttons;
->addColumn('actions', function ($blogcategory) {
return $blogcategory->action_buttons;
})
->make(true);
}
......
......@@ -18,8 +18,8 @@ class BlogCategoryEventListener
public function onCreated($event)
{
history()->withType($this->history_slug)
->withEntity($event->blogcategories->id)
->withText('trans("history.backend.blogcategories.created") <strong>'.$event->blogcategories->name.'</strong>')
->withEntity($event->blogcategory->id)
->withText('trans("history.backend.blogcategories.created") <strong>'.$event->blogcategory->name.'</strong>')
->withIcon('plus')
->withClass('bg-green')
->log();
......@@ -31,8 +31,8 @@ class BlogCategoryEventListener
public function onUpdated($event)
{
history()->withType($this->history_slug)
->withEntity($event->blogcategories->id)
->withText('trans("history.backend.blogcategories.updated") <strong>'.$event->blogcategories->name.'</strong>')
->withEntity($event->blogcategory->id)
->withText('trans("history.backend.blogcategories.updated") <strong>'.$event->blogcategory->name.'</strong>')
->withIcon('save')
->withClass('bg-aqua')
->log();
......@@ -44,8 +44,8 @@ class BlogCategoryEventListener
public function onDeleted($event)
{
history()->withType($this->history_slug)
->withEntity($event->blogcategories->id)
->withText('trans("history.backend.blogcategories.deleted") <strong>'.$event->blogcategories->name.'</strong>')
->withEntity($event->blogcategory->id)
->withText('trans("history.backend.blogcategories.deleted") <strong>'.$event->blogcategory->name.'</strong>')
->withIcon('trash')
->withClass('bg-maroon')
->log();
......
......@@ -29,6 +29,6 @@ class BlogCategory extends BaseModel
public function __construct(array $attributes = [])
{
parent::__construct($attributes);
$this->table = config('access.blog_categories_table');
$this->table = config('module.blog_categories.table');
}
}
......@@ -17,4 +17,24 @@ trait BlogCategoryAttribute
'.$this->getDeleteButtonAttribute('delete-blog-category', 'admin.blogcategories.destroy').'
</div>';
}
/**
* @return string
*/
public function getStatusLabelAttribute()
{
if ($this->isActive()) {
return "<label class='label label-success'>".trans('labels.general.active').'</label>';
}
return "<label class='label label-danger'>".trans('labels.general.inactive').'</label>';
}
/**
* @return bool
*/
public function isActive()
{
return $this->status == 1;
}
}
......@@ -11,11 +11,10 @@ class BlogMapCategory extends BaseModel
*
* @var string
*/
protected $table;
protected $table = 'blog_map_categories';
public function __construct(array $attributes = [])
{
parent::__construct($attributes);
$this->table = config('access.blog_map_categories_table');
}
}
......@@ -11,11 +11,10 @@ class BlogMapTag extends BaseModel
*
* @var string
*/
protected $table;
protected $table = 'blog_map_tags';
public function __construct(array $attributes = [])
{
parent::__construct($attributes);
$this->table = config('access.blog_map_tags');
}
}
......@@ -29,6 +29,6 @@ class BlogTag extends BaseModel
public function __construct(array $attributes = [])
{
parent::__construct($attributes);
$this->table = config('access.blog_tags_table');
$this->table = config('module.blog_tags.table');
}
}
......@@ -26,13 +26,13 @@ class BlogCategoriesRepository extends BaseRepository
public function getForDataTable()
{
return $this->query()
->leftjoin(config('access.users_table'), config('access.users_table').'.id', '=', config('access.blog_categories_table').'.created_by')
->leftjoin(config('access.users_table'), config('access.users_table').'.id', '=', config('module.blog_categories.table').'.created_by')
->select([
config('access.blog_categories_table').'.id',
config('access.blog_categories_table').'.name',
config('access.blog_categories_table').'.status',
config('access.blog_categories_table').'.created_by',
config('access.blog_categories_table').'.created_at',
config('module.blog_categories.table').'.id',
config('module.blog_categories.table').'.name',
config('module.blog_categories.table').'.status',
config('module.blog_categories.table').'.created_by',
config('module.blog_categories.table').'.created_at',
config('access.users_table').'.first_name as user_name',
]);
}
......@@ -40,7 +40,7 @@ class BlogCategoriesRepository extends BaseRepository
/**
* @param array $input
*
* @throws GeneralException
* @throws \App\Exceptions\GeneralException
*
* @return bool
*/
......@@ -49,16 +49,13 @@ class BlogCategoriesRepository extends BaseRepository
if ($this->query()->where('name', $input['name'])->first()) {
throw new GeneralException(trans('exceptions.backend.blogcategories.already_exists'));
}
DB::transaction(function () use ($input) {
$blogcategories = self::MODEL;
$blogcategories = new $blogcategories();
$blogcategories->name = $input['name'];
$blogcategories->status = (isset($input['status']) && $input['status'] == 1)
? 1 : 0;
$blogcategories->created_by = access()->user()->id;
$input['status'] = isset($input['status']) ? 1 : 0;
$input['created_by'] = access()->user()->id;
if ($blogcategories->save()) {
event(new BlogCategoryCreated($blogcategories));
if ($blogcategory = BlogCategory::create($input)) {
event(new BlogCategoryCreated($blogcategory));
return true;
}
......@@ -68,44 +65,41 @@ class BlogCategoriesRepository extends BaseRepository
}
/**
* @param Model $permission
* @param \App\Models\BlogCategories\BlogCategory $blogcategory
* @param $input
*
* @throws GeneralException
* @throws \App\Exceptions\GeneralException
*
* return bool
*/
public function update(Model $blogcategories, array $input)
public function update(BlogCategory $blogcategory, array $input)
{
if ($this->query()->where('name', $input['name'])->where('id', '!=', $blogcategories->id)->first()) {
if ($this->query()->where('name', $input['name'])->where('id', '!=', $blogcategory->id)->first()) {
throw new GeneralException(trans('exceptions.backend.blogcategories.already_exists'));
}
$blogcategories->name = $input['name'];
$blogcategories->status = (isset($input['status']) && $input['status'] == 1)
? 1 : 0;
$blogcategories->updated_by = access()->user()->id;
DB::transaction(function () use ($blogcategories, $input) {
if ($blogcategories->save()) {
event(new BlogCategoryUpdated($blogcategories));
DB::transaction(function () use ($blogcategory, $input) {
$input['status'] = isset($input['status']) ? 1 : 0;
$input['updated_by'] = access()->user()->id;
if ($blogcategory->update($input)) {
event(new BlogCategoryUpdated($blogcategory));
return true;
}
throw new GeneralException(
trans('exceptions.backend.blogcategories.update_error')
);
throw new GeneralException(trans('exceptions.backend.blogcategories.update_error'));
});
}
/**
* @param Model $blogcategory
* @param \App\Models\BlogCategories\BlogCategory $blogcategory
*
* @throws GeneralException
* @throws \App\Exceptions\GeneralException
*
* @return bool
*/
public function delete(Model $blogcategory)
public function delete(BlogCategory $blogcategory)
{
DB::transaction(function () use ($blogcategory) {
if ($blogcategory->delete()) {
......
......@@ -70,26 +70,6 @@ return [
*/
'history_types_table' => 'history_types',
/*
* Blog Catagories table used to store Blog Catagory
*/
'blog_categories_table' => 'blog_categories',
/*
* Blog Tags table used to store Blog Tag
*/
'blogs_table' => 'blogs',
/*
* Blog Tags table used to store Blog Tag
*/
'blog_map_categories_table' => 'blog_map_categories',
/*
* Blog Tags table used to store Blog Tag
*/
'blog_map_tags_table' => 'blog_map_tags',
/*
* Notifications table used to store user notification
*/
......
......@@ -11,5 +11,8 @@ return [
],
'blog_tags' => [
'table' => 'blog_tags'
],
'blog_categories' => [
'table' => 'blog_categories'
]
];
......@@ -17,7 +17,7 @@
<h3 class="box-title">{{ trans('labels.backend.blogcategories.create') }}</h3>
<div class="box-tools pull-right">
@include('backend.includes.partials.blogcategories-header-buttons')
@include('backend.blogcategories.partials.blogcategories-header-buttons')
</div><!--box-tools pull-right-->
</div><!-- /.box-header -->
......
......@@ -17,7 +17,7 @@
<h3 class="box-title">{{ trans('labels.backend.blogcategories.edit') }}</h3>
<div class="box-tools pull-right">
@include('backend.includes.partials.blogcategories-header-buttons')
@include('backend.blogcategories.partials.blogcategories-header-buttons')
</div><!--box-tools pull-right-->
</div><!-- /.box-header -->
......
......@@ -12,7 +12,7 @@
<h3 class="box-title">{{ trans('labels.backend.blogcategories.management') }}</h3>
<div class="box-tools pull-right">
@include('backend.includes.partials.blogcategories-header-buttons')
@include('backend.blogcategories.partials.blogcategories-header-buttons')
</div>
</div><!-- /.box-header -->
......@@ -74,10 +74,10 @@
type: 'post'
},
columns: [
{data: 'name', name: '{{config('access.blog_categories_table')}}.name'},
{data: 'status', name: '{{config('access.blog_categories_table')}}.status'},
{data: 'created_by', name: '{{config('access.blog_categories_table')}}.created_by'},
{data: 'created_at', name: '{{config('access.blog_categories_table')}}.created_at'},
{data: 'name', name: '{{config('module.blog_categories.table')}}.name'},
{data: 'status', name: '{{config('module.blog_categories.table')}}.status'},
{data: 'created_by', name: '{{config('module.blog_categories.table')}}.created_by'},
{data: 'created_at', name: '{{config('module.blog_categories.table')}}.created_at'},
{data: 'actions', name: 'actions', searchable: false, sortable: false}
],
order: [[3, "asc"]],
......
<!--Action Button-->
@if(Active::checkUriPattern('admin/blogtags'))
@if(Active::checkUriPattern('admin/blogcategories'))
<div class="btn-group">
<button type="button" class="btn btn-warning btn-flat dropdown-toggle" data-toggle="dropdown">Export
<span class="caret"></span>
......@@ -21,11 +21,9 @@
<span class="sr-only">Toggle Dropdown</span>
</button>
<ul class="dropdown-menu" role="menu">
<li><a href="{{route('admin.blogtags.index')}}"><i class="fa fa-list-ul"></i> {{trans('menus.backend.blogtags.all')}}</a></li>
@permission('create-blog-tag')
<li><a href="{{route('admin.blogtags.create')}}"><i class="fa fa-plus"></i> {{trans('menus.backend.blogtags.create')}}</a></li>
<li><a href="{{route('admin.blogcategories.index')}}"><i class="fa fa-list-ul"></i> {{trans('menus.backend.blogcategories.all')}}</a></li>
@permission('create-blog-category')
<li><a href="{{route('admin.blogcategories.create')}}"><i class="fa fa-plus"></i> {{trans('menus.backend.blogcategories.create')}}</a></li>
@endauth
</ul>
</div>
<div class="clearfix"></div>
</div>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment