Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Sign in
Toggle navigation
P
Project_Laravel
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
TTS Nguyen Huu Huan
Project_Laravel
Commits
f39ee5a5
Commit
f39ee5a5
authored
Sep 22, 2022
by
20194288-huannh
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update OrderController part 3
parent
d5f42690
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
13 additions
and
15 deletions
+13
-15
OrderController.php
app/Http/Controllers/Api/OrderController.php
+3
-3
OrderController.php
app/Http/Controllers/OrderController.php
+3
-4
GetOrderRequest.php
app/Http/Requests/GetOrderRequest.php
+2
-1
OrderRepository.php
app/Repositories/OrderRepository.php
+5
-7
No files found.
app/Http/Controllers/Api/OrderController.php
View file @
f39ee5a5
...
...
@@ -26,8 +26,8 @@ public function index(GetOrderRequest $request)
{
$user
=
auth
(
'api'
)
->
user
();
$order
=
$user
->
role
==
User
::
ROLE_ADMIN
?
$this
->
orderRepository
->
getListOrder
(
$request
->
all
())
->
paginate
()
:
$this
->
orderRepository
->
getListOrder
OfUser
(
$user
->
id
,
$request
->
all
()
);
$this
->
orderRepository
->
getListOrder
(
$request
->
all
())
:
$this
->
orderRepository
->
getListOrder
(
$request
->
all
(),
$user
->
id
);
return
response
()
->
json
([
'success'
=>
true
,
'meta'
=>
[
...
...
@@ -96,7 +96,7 @@ public function edit(Request $request)
* @param int $id
* @return \Illuminate\Http\Response
*/
public
function
update
(
Request
$request
,
$id
)
public
function
update
(
Request
$request
)
{
$is_update
=
$this
->
orderRepository
->
update
(
$request
->
id
,
...
...
app/Http/Controllers/OrderController.php
View file @
f39ee5a5
<?php
namespace
App\Http\Controllers
\Api
;
namespace
App\Http\Controllers
;
use
App\Http\Resources\OrderResource
;
use
App\Repositories\OrderRepository
;
use
App\Http\Controllers\Controller
;
use
App\Repositories\UserRepository
;
use
App\Http\Requests\GetOrderRequest
;
use
Illuminate\Http\Request
;
use
App\Models\User
;
...
...
@@ -26,8 +25,8 @@ public function index(GetOrderRequest $request)
{
$user
=
auth
(
'api'
)
->
user
();
$order
=
$user
->
role
==
User
::
ROLE_ADMIN
?
$this
->
orderRepository
->
getListOrder
(
$request
->
all
())
->
paginate
()
:
$this
->
orderRepository
->
getListOrder
OfUser
(
$user
->
id
,
$request
->
all
()
);
$this
->
orderRepository
->
getListOrder
(
$request
->
all
())
:
$this
->
orderRepository
->
getListOrder
(
$request
->
all
(),
$user
->
id
);
return
response
()
->
json
([
'success'
=>
true
,
'meta'
=>
[
...
...
app/Http/Requests/GetOrderRequest.php
View file @
f39ee5a5
...
...
@@ -24,7 +24,8 @@ public function authorize()
public
function
rules
()
{
return
[
'status'
=>
'integer'
'status'
=>
'integer'
,
'keyword'
=>
'max:255'
];
}
}
app/Repositories/OrderRepository.php
View file @
f39ee5a5
...
...
@@ -4,7 +4,6 @@
use
App\Models\Order
;
use
App\Repositories\BaseRepository
;
use
Log
;
class
OrderRepository
extends
BaseRepository
{
...
...
@@ -24,9 +23,12 @@ public function getFulfilledOrder()
$this
->
model
->
where
(
'is_fulfilled'
,
true
);
}
public
function
getListOrder
(
array
$params
)
public
function
getListOrder
(
array
$params
,
$id
=
0
)
{
$query
=
$this
->
model
;
if
(
!
$id
){
$query
=
$query
->
where
(
'user_id'
,
$id
);
}
if
(
isset
(
$params
[
'status'
]))
{
$query
=
$query
->
where
(
'status'
,
$params
[
'status'
]);
}
...
...
@@ -42,10 +44,6 @@ public function getListOrder(array $params)
});
});
}
return
$query
;
}
public
function
getListOrderOfUser
(
$id
,
array
$params
=
[])
{
return
$this
->
getListOrder
(
$params
)
->
where
(
'user_id'
,
$id
)
->
paginate
();
return
$query
->
paginate
();
}
}
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