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
d5f42690
Commit
d5f42690
authored
Sep 20, 2022
by
20194288-huannh
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update index function in OrderController
parent
9891271d
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
33 additions
and
24 deletions
+33
-24
OrderController.php
app/Http/Controllers/Api/OrderController.php
+4
-3
OrderController.php
app/Http/Controllers/OrderController.php
+10
-15
OrderRepository.php
app/Repositories/OrderRepository.php
+19
-6
No files found.
app/Http/Controllers/Api/OrderController.php
View file @
d5f42690
...
...
@@ -24,9 +24,10 @@ public function __construct(OrderRepository $orderRepository)
}
public
function
index
(
GetOrderRequest
$request
)
{
$user
=
auth
(
'api'
)
->
user
()
->
id
;
$order
=
$user
->
role
==
User
::
ROLE_ADMIN
?
$this
->
orderRepository
->
getListOrderOfAdmin
(
$request
->
all
())
:
$this
->
orderRepository
->
getListOrderOfUser
(
$user
);
$user
=
auth
(
'api'
)
->
user
();
$order
=
$user
->
role
==
User
::
ROLE_ADMIN
?
$this
->
orderRepository
->
getListOrder
(
$request
->
all
())
->
paginate
()
:
$this
->
orderRepository
->
getListOrderOfUser
(
$user
->
id
,
$request
->
all
());
return
response
()
->
json
([
'success'
=>
true
,
'meta'
=>
[
...
...
app/Http/Controllers/OrderController.php
View file @
d5f42690
...
...
@@ -24,17 +24,10 @@ public function __construct(OrderRepository $orderRepository)
}
public
function
index
(
GetOrderRequest
$request
)
{
$user
=
auth
(
'api'
)
->
user
()
->
id
;
switch
(
$user
->
role
)
{
case
User
::
ROLE_ADMIN
:
$order
=
$this
->
orderRepository
->
getListOrderOfAdmin
(
$request
->
all
());
break
;
case
User
::
ROLE_EDITOR
:
$order
=
$this
->
orderRepository
->
getListOrderOfUser
(
$user
);
break
;
default
:
$order
=
collect
([]);
}
$user
=
auth
(
'api'
)
->
user
();
$order
=
$user
->
role
==
User
::
ROLE_ADMIN
?
$this
->
orderRepository
->
getListOrder
(
$request
->
all
())
->
paginate
()
:
$this
->
orderRepository
->
getListOrderOfUser
(
$user
->
id
,
$request
->
all
());
return
response
()
->
json
([
'success'
=>
true
,
'meta'
=>
[
...
...
@@ -110,8 +103,9 @@ public function update(Request $request, $id)
$request
->
only
([
'id'
,
'details'
,
'client'
,
'is_fulfilled'
])
);
return
response
()
->
json
([
'success'
=>
$is_update
?
true
:
false
,
'message'
=>
''
'success'
=>
true
,
'message'
=>
''
,
'data'
=>
$is_update
]);
}
...
...
@@ -125,8 +119,9 @@ public function destroy(Request $request)
{
$is_deleted
=
$this
->
orderRepository
->
deleteById
(
$request
->
id
);
return
response
()
->
json
([
'success'
=>
$is_deleted
?
true
:
false
,
'message'
=>
''
'success'
=>
true
,
'message'
=>
''
,
'data'
=>
$is_deleted
]);
}
}
app/Repositories/OrderRepository.php
View file @
d5f42690
...
...
@@ -4,6 +4,7 @@
use
App\Models\Order
;
use
App\Repositories\BaseRepository
;
use
Log
;
class
OrderRepository
extends
BaseRepository
{
...
...
@@ -23,16 +24,28 @@ public function getFulfilledOrder()
$this
->
model
->
where
(
'is_fulfilled'
,
true
);
}
public
function
getListOrder
OfAdmin
(
array
$params
)
public
function
getListOrder
(
array
$params
)
{
$query
=
$this
->
model
;
foreach
(
$params
as
$key
=>
$value
)
{
$query
=
$query
->
where
(
$key
,
$value
);
if
(
isset
(
$params
[
'status'
])
)
{
$query
=
$query
->
where
(
'status'
,
$params
[
'status'
]
);
}
return
$query
->
paginate
();
if
(
isset
(
$params
[
'keyword'
]))
{
$keyword
=
$params
[
'keyword'
];
$query
=
$query
->
where
(
function
(
$query
)
use
(
$keyword
)
{
$query
->
where
(
'details'
,
'LIKE'
,
'%'
.
$keyword
.
'%'
)
->
orWhere
(
'client'
,
'LIKE'
,
'%'
.
$keyword
.
'%'
)
->
orWhere
(
function
(
$query
)
use
(
$keyword
)
{
$query
->
whereHas
(
'user'
,
function
(
$query
)
use
(
$keyword
)
{
$query
->
where
(
'name'
,
'LIKE'
,
'%'
.
$keyword
.
'%'
);
});
});
});
}
return
$query
;
}
public
function
getListOrderOfUser
(
$id
)
public
function
getListOrderOfUser
(
$id
,
array
$params
=
[]
)
{
return
$this
->
model
->
where
(
'user_id'
,
$id
)
->
with
(
'user'
)
->
paginate
();
return
$this
->
getListOrder
(
$params
)
->
where
(
'user_id'
,
$id
)
->
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