Unverified Commit 32d3c4b8 authored by Viral Solani's avatar Viral Solani Committed by GitHub

Merge pull request #54 from bvipul/vs_refactor_pages_module

Vs refactor pages module
parents 09259d9b e7e74e44
......@@ -8,7 +8,7 @@ require __DIR__.'/Search.php';
require __DIR__.'/Access/User.php';
require __DIR__.'/Access/Role.php';
require __DIR__.'/Access/Permission.php';
require __DIR__.'/CMS_Page.php';
require __DIR__.'/Page.php';
require __DIR__.'/Email_Template.php';
require __DIR__.'/Setting.php';
require __DIR__.'/Blog_Category.php';
......
<?php
Breadcrumbs::register('admin.cmspages.index', function ($breadcrumbs) {
$breadcrumbs->parent('admin.dashboard');
$breadcrumbs->push(trans('menus.backend.cmspages.management'), route('admin.cmspages.index'));
});
Breadcrumbs::register('admin.cmspages.create', function ($breadcrumbs) {
$breadcrumbs->parent('admin.cmspages.index');
$breadcrumbs->push(trans('menus.backend.cmspages.create'), route('admin.cmspages.create'));
});
Breadcrumbs::register('admin.cmspages.edit', function ($breadcrumbs, $id) {
$breadcrumbs->parent('admin.cmspages.index');
$breadcrumbs->push(trans('menus.backend.cmspages.edit'), route('admin.cmspages.edit', $id));
});
<?php
Breadcrumbs::register('admin.pages.index', function ($breadcrumbs) {
$breadcrumbs->parent('admin.dashboard');
$breadcrumbs->push(trans('menus.backend.pages.management'), route('admin.pages.index'));
});
Breadcrumbs::register('admin.pages.create', function ($breadcrumbs) {
$breadcrumbs->parent('admin.pages.index');
$breadcrumbs->push(trans('menus.backend.pages.create'), route('admin.pages.create'));
});
Breadcrumbs::register('admin.pages.edit', function ($breadcrumbs, $id) {
$breadcrumbs->parent('admin.pages.index');
$breadcrumbs->push(trans('menus.backend.pages.edit'), route('admin.pages.edit', $id));
});
......@@ -2,15 +2,15 @@
namespace App\Http\Controllers\Backend\Pages;
use App\Models\Page\Page;
use App\Http\Controllers\Controller;
use App\Repositories\Backend\Pages\PagesRepository;
use App\Http\Requests\Backend\Pages\EditPageRequest;
use App\Http\Requests\Backend\Pages\StorePageRequest;
use App\Http\Requests\Backend\Pages\CreatePageRequest;
use App\Http\Requests\Backend\Pages\DeletePageRequest;
use App\Http\Requests\Backend\Pages\EditPageRequest;
use App\Http\Requests\Backend\Pages\ManagePageRequest;
use App\Http\Requests\Backend\Pages\StorePageRequest;
use App\Http\Requests\Backend\Pages\UpdatePageRequest;
use App\Models\Page\Page;
use App\Repositories\Backend\Pages\PagesRepository;
/**
* Class PagesController.
......@@ -23,7 +23,7 @@ class PagesController extends Controller
protected $pages;
/**
* @param PagesRepository $pages
* @param \App\Repositories\Backend\Pages\PagesRepository $pages
*/
public function __construct(PagesRepository $pages)
{
......@@ -31,7 +31,7 @@ class PagesController extends Controller
}
/**
* @param ManagePageRequest $request
* @param \App\Http\Requests\Backend\Pages\ManagePageRequest $request
*
* @return mixed
*/
......@@ -41,7 +41,7 @@ class PagesController extends Controller
}
/**
* @param CreatePageRequest $request
* @param \App\Http\Requests\Backend\Pages\CreatePageRequest $request
*
* @return mixed
*/
......@@ -51,45 +51,45 @@ class PagesController extends Controller
}
/**
* @param StorePageRequest $request
* @param \App\Http\Requests\Backend\Pages\StorePageRequest $request
*
* @return mixed
*/
public function store(StorePageRequest $request)
{
$this->pages->create($request->all());
$this->pages->create($request->except(['_token']));
return redirect()->route('admin.pages.index')->withFlashSuccess(trans('alerts.backend.pages.created'));
}
/**
* @param Page $page
* @param EditPageRequest $request
* @param \App\Models\Page\Page $page
* @param \App\Http\Requests\Backend\Pages\EditPageRequest $request
*
* @return mixed
*/
public function edit(Page $page, EditPageRequest $request)
{
return view('backend.pages.edit')
->withCmspage($page);
->withPage($page);
}
/**
* @param Page $page
* @param UpdatePageRequest $request
* @param \App\Models\Page\Page $page
* @param \App\Http\Requests\Backend\Pages\UpdatePageRequest $request
*
* @return mixed
*/
public function update(Page $page, UpdatePageRequest $request)
{
$this->pages->update($page, $request->all());
$this->pages->update($page, $request->except(['_method', '_token']));
return redirect()->route('admin.pages.index')->withFlashSuccess(trans('alerts.backend.pages.updated'));
}
/**
* @param Page $page
* @param DeletePageRequest $request
* @param \App\Models\Page\Page $page
* @param \App\Http\Requests\Backend\Pages\DeletePageRequest $request
*
* @return mixed
*/
......
......@@ -2,11 +2,11 @@
namespace App\Http\Controllers\Backend\Pages;
use App\Http\Controllers\Controller;
use App\Http\Requests\Backend\Pages\ManagePageRequest;
use App\Repositories\Backend\Pages\PagesRepository;
use Carbon\Carbon;
use App\Http\Controllers\Controller;
use Yajra\DataTables\Facades\DataTables;
use App\Repositories\Backend\Pages\PagesRepository;
use App\Http\Requests\Backend\Pages\ManagePageRequest;
/**
* Class PagesTableController.
......@@ -36,11 +36,7 @@ class PagesTableController extends Controller
return Datatables::of($this->pages->getForDataTable())
->escapeColumns(['title'])
->addColumn('status', function ($pages) {
if ($pages->status) {
return '<span class="label label-success">Active</span>';
}
return '<span class="label label-danger">Inactive</span>';
return $pages->status_label;
})
->addColumn('created_at', function ($pages) {
return Carbon::parse($pages->created_at)->toDateString();
......
......@@ -4,8 +4,8 @@ namespace App\Models\Page;
use App\Models\BaseModel;
use App\Models\ModelTrait;
use App\Models\Page\Traits\Attribute\PageAttribute;
use Illuminate\Database\Eloquent\SoftDeletes;
use App\Models\Page\Traits\Attribute\PageAttribute;
class Page extends BaseModel
{
......@@ -22,9 +22,16 @@ class Page extends BaseModel
*/
protected $table;
/**
* The guarded field which are not mass assignable.
*
* @var array
*/
protected $guarded = ['id'];
public function __construct(array $attributes = [])
{
parent::__construct($attributes);
$this->table = config('access.cms_pages_table');
$this->table = config('module.pages.table');
}
}
......@@ -17,4 +17,24 @@ trait PageAttribute
'.$this->getDeleteButtonAttribute('delete-cms-pages', 'admin.pages.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;
}
}
......@@ -2,13 +2,12 @@
namespace App\Repositories\Backend\Pages;
use App\Models\Page\Page;
use App\Exceptions\GeneralException;
use App\Repositories\BaseRepository;
use App\Events\Backend\Pages\PageCreated;
use App\Events\Backend\Pages\PageDeleted;
use App\Events\Backend\Pages\PageUpdated;
use App\Exceptions\GeneralException;
use App\Models\Page\Page;
use App\Repositories\BaseRepository;
use DB;
/**
* Class PagesRepository.
......@@ -27,18 +26,18 @@ class PagesRepository extends BaseRepository
{
return $this->query()
->select([
config('access.pages_table').'.id',
config('access.pages_table').'.title',
config('access.pages_table').'.status',
config('access.pages_table').'.created_at',
config('access.pages_table').'.updated_at',
config('module.pages.table').'.id',
config('module.pages.table').'.title',
config('module.pages.table').'.status',
config('module.pages.table').'.created_at',
config('module.pages.table').'.updated_at',
]);
}
/**
* @param array $input
*
* @throws GeneralException
* @throws \App\Exceptions\GeneralException
*
* @return bool
*/
......@@ -48,80 +47,62 @@ class PagesRepository extends BaseRepository
throw new GeneralException(trans('exceptions.backend.pages.already_exists'));
}
DB::transaction(function () use ($input) {
$pages = self::MODEL;
$pages = new $pages();
$pages->title = $input['title'];
$pages->page_slug = str_slug($input['title']);
$pages->description = $input['description'];
$pages->cannonical_link = $input['cannonical_link'];
$pages->seo_title = $input['seo_title'];
$pages->seo_keyword = $input['seo_keyword'];
$pages->seo_description = $input['seo_description'];
$pages->status = (isset($input['status']) && $input['status'] == 1) ? 1 : 0;
$pages->created_by = access()->user()->id;
if ($pages->save()) {
event(new PageCreated($pages));
//Making extra fields
$input['page_slug'] = str_slug($input['title']);
$input['status'] = isset($input['status']) ? 1 : 0;
$input['created_by'] = access()->user()->id;
if( $page = Page::create($input) ) {
event(new PageCreated($page));
return true;
}
throw new GeneralException(trans('exceptions.backend.pages.create_error'));
});
}
/**
* @param Model $permission
* @param $input
* @param \App\Models\Page\Page $page
* @param array $input
*
* @throws GeneralException
* @throws \App\Exceptions\GeneralException
*
* return bool
* @return bool
*/
public function update(Model $page, array $input)
public function update($page, array $input)
{
if ($this->query()->where('title', $input['title'])->where('id', '!=', $page->id)->first()) {
throw new GeneralException(trans('exceptions.backend.pages.already_exists'));
}
$page->title = $input['title'];
$page->page_slug = str_slug($input['title']);
$page->description = $input['description'];
$page->cannonical_link = $input['cannonical_link'];
$page->seo_title = $input['seo_title'];
$page->seo_keyword = $input['seo_keyword'];
$page->seo_description = $input['seo_description'];
$page->status = (isset($input['status']) && $input['status'] == 1) ? 1 : 0;
$page->updated_by = access()->user()->id;
DB::transaction(function () use ($page, $input) {
if ($page->save()) {
//Making extra fields
$input['page_slug'] = str_slug($input['title']);
$input['status'] = isset($input['status']) ? 1 : 0;
$input['updated_by'] = access()->user()->id;
if ( $page->update($input) ) {
event(new PageUpdated($page));
return true;
}
throw new GeneralException(trans('exceptions.backend.pages.update_error'));
});
}
/**
* @param Model $page
* @param \App\Models\Page\Page $page
*
* @throws GeneralException
* @throws \App\Exceptions\GeneralException
*
* @return bool
*/
public function delete(Model $page)
public function delete($page)
{
DB::transaction(function () use ($page) {
if ($page->delete()) {
if ( $page->delete() ) {
event(new PageDeleted($page));
return true;
}
throw new GeneralException(trans('exceptions.backend.pages.delete_error'));
});
}
}
......@@ -60,11 +60,6 @@ return [
*/
'cities_table' => 'cities',
/*
* cmspages table used to store cmspages
*/
'pages_table' => 'pages',
/*
* email template placeholders table used to store email template placeholders
*/
......
<?php
return [
'pages' => [
'table' => 'pages'
]
];
\ No newline at end of file
......@@ -10,7 +10,7 @@
@endsection
@section('content')
{{ Form::model($cmspage, ['route' => ['admin.pages.update', $cmspage], 'class' => 'form-horizontal', 'role' => 'form', 'method' => 'PATCH', 'id' => 'edit-role']) }}
{{ Form::model($page, ['route' => ['admin.pages.update', $page], 'class' => 'form-horizontal', 'role' => 'form', 'method' => 'PATCH', 'id' => 'edit-role']) }}
<div class="box box-success">
<div class="box-header with-border">
......@@ -76,7 +76,7 @@
<div class="col-lg-10">
<div class="control-group">
<label class="control control--checkbox">
{{ Form::checkbox('status', 1, ($cmspage->status == 1) ? true : false ) }}
{{ Form::checkbox('status', 1, ($page->status == 1) ? true : false ) }}
<div class="control__indicator"></div>
</label>
</div>
......
......@@ -74,10 +74,10 @@
type: 'post'
},
columns: [
{data: 'title', name: '{{config('access.pages_table')}}.title'},
{data: 'status', name: '{{config('access.pages_table')}}.status'},
{data: 'created_at', name: '{{config('access.pages_table')}}.created_at'},
{data: 'updated_at', name: '{{config('access.pages_table')}}.updated_at'},
{data: 'title', name: '{{config('module.pages.table')}}.title'},
{data: 'status', name: '{{config('module.pages.table')}}.status'},
{data: 'created_at', name: '{{config('module.pages.table')}}.created_at'},
{data: 'updated_at', name: '{{config('module.pages.table')}}.updated_at'},
{data: 'actions', name: 'actions', searchable: false, sortable: false}
],
order: [[3, "asc"]],
......
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