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
8c72d8d7
Commit
8c72d8d7
authored
Mar 08, 2018
by
cygnet
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
changes done for the FAQ apis
parent
ca885d91
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
145 additions
and
0 deletions
+145
-0
FaqsController.php
app/Http/Controllers/Api/V1/FaqsController.php
+115
-0
FaqsResource.php
app/Http/Resources/FaqsResource.php
+27
-0
api.php
routes/api.php
+3
-0
No files found.
app/Http/Controllers/Api/V1/FaqsController.php
0 → 100755
View file @
8c72d8d7
<?php
namespace
App\Http\Controllers\Api\V1
;
use
App\Http\Resources\FaqsResource
;
use
App\Models\Faqs\Faq
;
use
App\Repositories\Backend\Faqs\FaqsRepository
;
use
Illuminate\Http\Request
;
use
Validator
;
class
FaqsController
extends
APIController
{
protected
$repository
;
/**
* __construct.
*
* @param $repository
*/
public
function
__construct
(
FaqsRepository
$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
FaqsResource
::
collection
(
$this
->
repository
->
getForDataTable
()
->
paginate
(
$limit
)
);
}
/**
* Return the specified resource.
*
* @param User $user
*
* @return \Illuminate\Http\Response
*/
public
function
show
(
Faq
$faq
)
{
return
new
FaqsResource
(
$faq
);
}
/**
* Creates the Resource for Faq.
*
* @param Request $request
*
* @return \Illuminate\Http\Response
*/
public
function
store
(
Request
$request
)
{
$validation
=
$this
->
validatingRequest
(
$request
);
if
(
$validation
->
fails
())
{
return
$this
->
throwValidation
(
$validation
->
messages
()
->
first
());
}
$this
->
repository
->
create
(
$request
->
all
());
return
new
FaqsResource
(
Faq
::
orderBy
(
'created_at'
,
'desc'
)
->
first
());
}
/**
* @param Faq $faq
* @param UpdateFaqRequest $request
*
* @return mixed
*/
public
function
update
(
Request
$request
,
Faq
$faq
)
{
$validation
=
$this
->
validatingRequest
(
$request
);
if
(
$validation
->
fails
())
{
return
$this
->
throwValidation
(
$validation
->
messages
()
->
first
());
}
$this
->
repository
->
update
(
$faq
,
$request
->
all
());
$faq
=
Faq
::
findOrfail
(
$faq
->
id
);
return
new
FaqsResource
(
$faq
);
}
public
function
validatingRequest
(
Request
$request
)
{
$validation
=
Validator
::
make
(
$request
->
all
(),
[
'question'
=>
'required|max:191'
,
'answer'
=>
'required'
,
]);
return
$validation
;
}
/**
* @param Faq $faq
* @param DeleteFaqRequest $request
*
* @return mixed
*/
public
function
destroy
(
Faq
$faq
,
Request
$request
)
{
$this
->
repository
->
delete
(
$faq
);
return
[
'message'
=>
'success'
];
}
}
app/Http/Resources/FaqsResource.php
0 → 100644
View file @
8c72d8d7
<?php
namespace
App\Http\Resources
;
use
Illuminate\Http\Resources\Json\Resource
;
class
FaqsResource
extends
Resource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request
*
* @return array
*/
public
function
toArray
(
$request
)
{
return
[
'id'
=>
$this
->
id
,
'question'
=>
$this
->
question
,
'answer'
=>
$this
->
answer
,
'status'
=>
$this
->
status
,
'created_at'
=>
$this
->
created_at
->
toIso8601String
(),
];
}
}
routes/api.php
View file @
8c72d8d7
...
@@ -42,5 +42,8 @@ Route::group(['namespace' => 'Api\V1', 'prefix' => 'v1', 'as' => 'v1.'], functio
...
@@ -42,5 +42,8 @@ Route::group(['namespace' => 'Api\V1', 'prefix' => 'v1', 'as' => 'v1.'], functio
// Page
// Page
Route
::
resource
(
'pages'
,
'PagesController'
);
Route
::
resource
(
'pages'
,
'PagesController'
);
// Faqs
Route
::
resource
(
'faqs'
,
'FaqsController'
);
});
});
});
});
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