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
ce005fdb
Commit
ce005fdb
authored
Dec 29, 2017
by
bvipul
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Completed Unit test for Pages and added created by relationship in Page with User
parent
130e2c18
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
68 additions
and
16 deletions
+68
-16
PagesTableController.php
app/Http/Controllers/Backend/Pages/PagesTableController.php
+8
-8
Page.php
app/Models/Page/Page.php
+14
-1
PageAttribute.php
app/Models/Page/Traits/Attribute/PageAttribute.php
+2
-2
PageRelationship.php
app/Models/Page/Traits/PageRelationship.php
+14
-0
PagesRepository.php
app/Repositories/Backend/Pages/PagesRepository.php
+4
-2
labels.php
resources/lang/en/labels.php
+1
-0
index.blade.php
resources/views/backend/pages/index.blade.php
+3
-3
PageTest.php
tests/Unit/PageTest.php
+22
-0
No files found.
app/Http/Controllers/Backend/Pages/PagesTableController.php
View file @
ce005fdb
...
@@ -32,17 +32,17 @@ class PagesTableController extends Controller
...
@@ -32,17 +32,17 @@ class PagesTableController extends Controller
{
{
return
Datatables
::
of
(
$this
->
pages
->
getForDataTable
())
return
Datatables
::
of
(
$this
->
pages
->
getForDataTable
())
->
escapeColumns
([
'title'
])
->
escapeColumns
([
'title'
])
->
addColumn
(
'status'
,
function
(
$page
s
)
{
->
addColumn
(
'status'
,
function
(
$page
)
{
return
$page
s
->
status_label
;
return
$page
->
status_label
;
})
})
->
addColumn
(
'created_at'
,
function
(
$page
s
)
{
->
addColumn
(
'created_at'
,
function
(
$page
)
{
return
Carbon
::
parse
(
$pages
->
created_at
)
->
toDateString
();
return
$page
->
created_at
->
toDateString
();
})
})
->
addColumn
(
'
updated_at'
,
function
(
$pages
)
{
->
addColumn
(
'
created_by'
,
function
(
$page
)
{
return
Carbon
::
parse
(
$pages
->
updated_at
)
->
toDateString
()
;
return
$page
->
created_by
;
})
})
->
addColumn
(
'actions'
,
function
(
$page
s
)
{
->
addColumn
(
'actions'
,
function
(
$page
)
{
return
$page
s
->
action_buttons
;
return
$page
->
action_buttons
;
})
})
->
make
(
true
);
->
make
(
true
);
}
}
...
...
app/Models/Page/Page.php
View file @
ce005fdb
...
@@ -4,13 +4,15 @@ namespace App\Models\Page;
...
@@ -4,13 +4,15 @@ namespace App\Models\Page;
use
App\Models\BaseModel
;
use
App\Models\BaseModel
;
use
App\Models\ModelTrait
;
use
App\Models\ModelTrait
;
use
App\Models\Page\Traits\
Attribute\PageAttribute
;
use
App\Models\Page\Traits\
PageRelationship
;
use
Illuminate\Database\Eloquent\SoftDeletes
;
use
Illuminate\Database\Eloquent\SoftDeletes
;
use
App\Models\Page\Traits\Attribute\PageAttribute
;
class
Page
extends
BaseModel
class
Page
extends
BaseModel
{
{
use
ModelTrait
,
use
ModelTrait
,
SoftDeletes
,
SoftDeletes
,
PageRelationship
,
PageAttribute
{
PageAttribute
{
// PageAttribute::getEditButtonAttribute insteadof ModelTrait;
// PageAttribute::getEditButtonAttribute insteadof ModelTrait;
}
}
...
@@ -29,6 +31,17 @@ class Page extends BaseModel
...
@@ -29,6 +31,17 @@ class Page extends BaseModel
*/
*/
protected
$guarded
=
[
'id'
];
protected
$guarded
=
[
'id'
];
/**
* The default values for attributes
*
* @var array
*/
protected
$attributes
=
[
'created_by'
=>
1
];
protected
$with
=
[
'owner'
];
public
function
__construct
(
array
$attributes
=
[])
public
function
__construct
(
array
$attributes
=
[])
{
{
parent
::
__construct
(
$attributes
);
parent
::
__construct
(
$attributes
);
...
...
app/Models/Page/Traits/Attribute/PageAttribute.php
View file @
ce005fdb
...
@@ -13,8 +13,8 @@ trait PageAttribute
...
@@ -13,8 +13,8 @@ trait PageAttribute
public
function
getActionButtonsAttribute
()
public
function
getActionButtonsAttribute
()
{
{
return
'<div class="btn-group action-btn">
return
'<div class="btn-group action-btn">
'
.
$this
->
getEditButtonAttribute
(
'edit-
cms-pages
'
,
'admin.pages.edit'
)
.
'
'
.
$this
->
getEditButtonAttribute
(
'edit-
page
'
,
'admin.pages.edit'
)
.
'
'
.
$this
->
getDeleteButtonAttribute
(
'delete-
cms-pages
'
,
'admin.pages.destroy'
)
.
'
'
.
$this
->
getDeleteButtonAttribute
(
'delete-
page
'
,
'admin.pages.destroy'
)
.
'
</div>'
;
</div>'
;
}
}
...
...
app/Models/Page/Traits/PageRelationship.php
0 → 100644
View file @
ce005fdb
<?php
namespace
App\Models\Page\Traits
;
use
App\Models\Access\User\User
;
trait
PageRelationship
{
public
function
owner
()
{
return
$this
->
belongsTo
(
User
::
class
,
'created_by'
);
}
}
\ No newline at end of file
app/Repositories/Backend/Pages/PagesRepository.php
View file @
ce005fdb
...
@@ -25,12 +25,14 @@ class PagesRepository extends BaseRepository
...
@@ -25,12 +25,14 @@ class PagesRepository 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
(
'module.pages.table'
)
.
'.created_by'
)
->
select
([
->
select
([
config
(
'module.pages.table'
)
.
'.id'
,
config
(
'module.pages.table'
)
.
'.id'
,
config
(
'module.pages.table'
)
.
'.title'
,
config
(
'module.pages.table'
)
.
'.title'
,
config
(
'module.pages.table'
)
.
'.status'
,
config
(
'module.pages.table'
)
.
'.status'
,
config
(
'module.pages.table'
)
.
'.created_at'
,
config
(
'module.pages.table'
)
.
'.created_at'
,
config
(
'module.pages.table'
)
.
'.updated_at'
,
config
(
'module.pages.table'
)
.
'.updated_at'
,
config
(
'access.users_table'
)
.
'.first_name as created_by'
]);
]);
}
}
...
@@ -47,7 +49,7 @@ class PagesRepository extends BaseRepository
...
@@ -47,7 +49,7 @@ class PagesRepository extends BaseRepository
throw
new
GeneralException
(
trans
(
'exceptions.backend.pages.already_exists'
));
throw
new
GeneralException
(
trans
(
'exceptions.backend.pages.already_exists'
));
}
}
//Making extra fields
//
Making extra fields
$input
[
'page_slug'
]
=
str_slug
(
$input
[
'title'
]);
$input
[
'page_slug'
]
=
str_slug
(
$input
[
'title'
]);
$input
[
'status'
]
=
isset
(
$input
[
'status'
])
?
1
:
0
;
$input
[
'status'
]
=
isset
(
$input
[
'status'
])
?
1
:
0
;
$input
[
'created_by'
]
=
auth
()
->
id
();
$input
[
'created_by'
]
=
auth
()
->
id
();
...
@@ -75,7 +77,7 @@ class PagesRepository extends BaseRepository
...
@@ -75,7 +77,7 @@ class PagesRepository extends BaseRepository
throw
new
GeneralException
(
trans
(
'exceptions.backend.pages.already_exists'
));
throw
new
GeneralException
(
trans
(
'exceptions.backend.pages.already_exists'
));
}
}
//Making extra fields
//
Making extra fields
$input
[
'page_slug'
]
=
str_slug
(
$input
[
'title'
]);
$input
[
'page_slug'
]
=
str_slug
(
$input
[
'title'
]);
$input
[
'status'
]
=
isset
(
$input
[
'status'
])
?
1
:
0
;
$input
[
'status'
]
=
isset
(
$input
[
'status'
])
?
1
:
0
;
$input
[
'updated_by'
]
=
access
()
->
user
()
->
id
;
$input
[
'updated_by'
]
=
access
()
->
user
()
->
id
;
...
...
resources/lang/en/labels.php
View file @
ce005fdb
...
@@ -126,6 +126,7 @@ return [
...
@@ -126,6 +126,7 @@ return [
'status'
=>
'Status'
,
'status'
=>
'Status'
,
'createdat'
=>
'Created At'
,
'createdat'
=>
'Created At'
,
'updatedat'
=>
'Updated At'
,
'updatedat'
=>
'Updated At'
,
'createdby'
=>
'Created By'
,
'all'
=>
'All'
,
'all'
=>
'All'
,
],
],
],
],
...
...
resources/views/backend/pages/index.blade.php
View file @
ce005fdb
...
@@ -24,7 +24,7 @@
...
@@ -24,7 +24,7 @@
<th>{{ trans('labels.backend.pages.table.title') }}</th>
<th>{{ trans('labels.backend.pages.table.title') }}</th>
<th>{{ trans('labels.backend.pages.table.status') }}</th>
<th>{{ trans('labels.backend.pages.table.status') }}</th>
<th>{{ trans('labels.backend.pages.table.createdat') }}</th>
<th>{{ trans('labels.backend.pages.table.createdat') }}</th>
<th>{{ trans('labels.backend.pages.table.
updatedat
') }}</th>
<th>{{ trans('labels.backend.pages.table.
createdby
') }}</th>
<th>{{ trans('labels.general.actions') }}</th>
<th>{{ trans('labels.general.actions') }}</th>
</tr>
</tr>
</thead>
</thead>
...
@@ -77,10 +77,10 @@
...
@@ -77,10 +77,10 @@
{data: 'title', name: '
{
{config('module.pages.table')}}.title'
}
,
{data: 'title', name: '
{
{config('module.pages.table')}}.title'
}
,
{data: 'status', name: '
{
{config('module.pages.table')}}.status'
}
,
{data: 'status', name: '
{
{config('module.pages.table')}}.status'
}
,
{data: 'created_at', name: '
{
{config('module.pages.table')}}.created_at'
}
,
{data: 'created_at', name: '
{
{config('module.pages.table')}}.created_at'
}
,
{data: '
updated_at', name: '
{
{config('module.pages.table')}}.updated_at
'
}
,
{data: '
created_by', name: '
{
{config('access.users_table')}}.first_name
'
}
,
{data: 'actions', name: 'actions', searchable: false, sortable: false}
{data: 'actions', name: 'actions', searchable: false, sortable: false}
],
],
order: [[
3
, "
asc
"]],
order: [[
1
, "
asc
"]],
searchDelay: 500,
searchDelay: 500,
dom: 'lBfrtip',
dom: 'lBfrtip',
buttons: {
buttons: {
...
...
tests/Unit/PageTest.php
0 → 100644
View file @
ce005fdb
<?php
namespace
Tests\Unit
;
use
Tests\TestCase
;
use
App\Models\Page\Page
;
use
App\Models\Access\User\User
;
use
Illuminate\Foundation\Testing\WithFaker
;
use
Illuminate\Foundation\Testing\RefreshDatabase
;
class
PageTest
extends
TestCase
{
/** @test */
public
function
it_has_an_owner
()
{
$this
->
actingAs
(
$this
->
admin
);
$page
=
create
(
Page
::
class
);
$this
->
assertInstanceOf
(
User
::
class
,
$page
->
owner
);
}
}
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