Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
L
laravel-adminpanel
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
laravel-adminpanel
Commits
6e849abe
Commit
6e849abe
authored
Nov 30, 2017
by
Vipul Basapati
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactored Pages Module
parent
faa59fc4
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
106 additions
and
100 deletions
+106
-100
PagesController.php
app/Http/Controllers/Backend/Pages/PagesController.php
+17
-17
PagesTableController.php
app/Http/Controllers/Backend/Pages/PagesTableController.php
+4
-8
Page.php
app/Models/Page/Page.php
+9
-2
PageAttribute.php
app/Models/Page/Traits/Attribute/PageAttribute.php
+20
-0
PagesRepository.php
app/Repositories/Backend/Pages/PagesRepository.php
+43
-62
access.php
config/access.php
+0
-5
module.php
config/module.php
+7
-0
edit.blade.php
resources/views/backend/pages/edit.blade.php
+2
-2
index.blade.php
resources/views/backend/pages/index.blade.php
+4
-4
No files found.
app/Http/Controllers/Backend/Pages/PagesController.php
View file @
6e849abe
...
...
@@ -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'
)
->
with
Cmsp
age
(
$page
);
->
with
P
age
(
$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
*/
...
...
app/Http/Controllers/Backend/Pages/PagesTableController.php
View file @
6e849abe
...
...
@@ -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
();
...
...
app/Models/Page/Page.php
View file @
6e849abe
...
...
@@ -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'
);
}
}
app/Models/Page/Traits/Attribute/PageAttribute.php
View file @
6e849abe
...
...
@@ -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
;
}
}
app/Repositories/Backend/Pages/PagesRepository.php
View file @
6e849abe
...
...
@@ -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
*/
...
...
@@ -47,81 +46,63 @@ class PagesRepository extends BaseRepository
if
(
$this
->
query
()
->
where
(
'title'
,
$input
[
'title'
])
->
first
())
{
throw
new
GeneralException
(
trans
(
'exceptions.backend.pages.already_exists'
));
}
//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
;
}
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
));
return
true
;
}
throw
new
GeneralException
(
trans
(
'exceptions.backend.pages.create_error'
));
});
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
())
{
event
(
new
PageUpdated
(
$page
));
//Making extra fields
$input
[
'page_slug'
]
=
str_slug
(
$input
[
'title'
]);
$input
[
'status'
]
=
isset
(
$input
[
'status'
])
?
1
:
0
;
$input
[
'updated_by'
]
=
access
()
->
user
()
->
id
;
return
true
;
}
if
(
$page
->
update
(
$input
)
)
{
event
(
new
PageUpdated
(
$page
));
throw
new
GeneralException
(
trans
(
'exceptions.backend.pages.update_error'
));
});
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
())
{
event
(
new
PageDeleted
(
$page
));
if
(
$page
->
delete
()
)
{
event
(
new
PageDeleted
(
$page
));
return
true
;
}
return
true
;
}
throw
new
GeneralException
(
trans
(
'exceptions.backend.pages.delete_error'
));
});
throw
new
GeneralException
(
trans
(
'exceptions.backend.pages.delete_error'
));
}
}
config/access.php
View file @
6e849abe
...
...
@@ -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
*/
...
...
config/module.php
0 → 100644
View file @
6e849abe
<?php
return
[
'pages'
=>
[
'table'
=>
'pages'
]
];
\ No newline at end of file
resources/views/backend/pages/edit.blade.php
View file @
6e849abe
...
...
@@ -10,7 +10,7 @@
@
endsection
@
section
(
'content'
)
{{
Form
::
model
(
$
cmspage
,
[
'route'
=>
[
'admin.pages.update'
,
$cms
page
],
'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, (
$
cms
page->status
== 1) ? true : false ) }}
{{ Form::checkbox('status', 1, (
$page->status
== 1) ? true : false ) }}
<div class="
control__indicator
"></div>
</label>
</div>
...
...
resources/views/backend/pages/index.blade.php
View file @
6e849abe
...
...
@@ -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
"]],
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment