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

Refactored Blog Category Module

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