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
ca885d91
Commit
ca885d91
authored
Mar 08, 2018
by
cygnet
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
changes done for the pages api
parent
9c33c597
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
143 additions
and
0 deletions
+143
-0
PagesController.php
app/Http/Controllers/Api/V1/PagesController.php
+115
-0
PagesResource.php
app/Http/Resources/PagesResource.php
+28
-0
No files found.
app/Http/Controllers/Api/V1/PagesController.php
0 → 100644
View file @
ca885d91
<?php
namespace
App\Http\Controllers\Api\V1
;
use
App\Http\Resources\PagesResource
;
use
App\Models\Page\Page
;
use
App\Repositories\Backend\Pages\PagesRepository
;
use
Illuminate\Http\Request
;
use
Validator
;
class
PagesController
extends
APIController
{
protected
$repository
;
/**
* __construct.
*
* @param $repository
*/
public
function
__construct
(
PagesRepository
$repository
)
{
$this
->
repository
=
$repository
;
}
/**
* Return the users.
*
* @return \Illuminate\Http\Response
*/
public
function
index
(
Request
$request
)
{
$limit
=
$request
->
get
(
'paginate'
)
?
$request
->
get
(
'paginate'
)
:
25
;
return
PagesResource
::
collection
(
$this
->
repository
->
getForDataTable
()
->
paginate
(
$limit
)
);
}
/**
* Return the specified resource.
*
* @param User $user
*
* @return \Illuminate\Http\Response
*/
public
function
show
(
Page
$page
)
{
return
new
PagesResource
(
$page
);
}
/**
* Creates the Resourse for Page.
*
* @param Request $request
*
* @return \Illuminate\Http\Response
*/
public
function
store
(
Request
$request
)
{
$validation
=
$this
->
valiatingRequest
(
$request
);
if
(
$validation
->
fails
())
{
return
$this
->
throwValidation
(
$validation
->
messages
()
->
first
());
}
$this
->
repository
->
create
(
$request
->
all
());
return
new
PagesResource
(
Page
::
orderBy
(
'created_at'
,
'desc'
)
->
first
());
}
/**
* @param Page $page
* @param UpdatePageRequest $request
*
* @return mixed
*/
public
function
update
(
Request
$request
,
Page
$page
)
{
$validation
=
$this
->
valiatingRequest
(
$request
);
if
(
$validation
->
fails
())
{
return
$this
->
throwValidation
(
$validation
->
messages
()
->
first
());
}
$this
->
repository
->
update
(
$page
,
$request
->
all
());
$page
=
Page
::
findOrfail
(
$page
->
id
);
return
new
PagesResource
(
$page
);
}
public
function
valiatingRequest
(
Request
$request
)
{
$validation
=
Validator
::
make
(
$request
->
all
(),
[
'title'
=>
'required|max:191'
,
'description'
=>
'required'
,
]);
return
$validation
;
}
/**
* @param Page $page
* @param DeletePageRequest $request
*
* @return mixed
*/
public
function
destroy
(
Page
$page
,
Request
$request
)
{
$this
->
repository
->
delete
(
$page
);
return
[
'message'
=>
'success'
];
}
}
app/Http/Resources/PagesResource.php
0 → 100644
View file @
ca885d91
<?php
namespace
App\Http\Resources
;
use
Illuminate\Http\Resources\Json\Resource
;
class
PagesResource
extends
Resource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request
*
* @return array
*/
public
function
toArray
(
$request
)
{
return
[
'id'
=>
$this
->
id
,
'title'
=>
$this
->
title
,
'status_label'
=>
$this
->
status_label
,
'status'
=>
(
$this
->
isActive
())
?
"Active"
:
"InActive"
,
'created_at'
=>
$this
->
created_at
->
toDateString
(),
'created_by'
=>
is_int
(
$this
->
created_by
)
?
optional
(
$this
->
owner
)
->
first_name
:
$this
->
created_by
,
];
}
}
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