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
2057d743
Commit
2057d743
authored
Sep 19, 2022
by
20194288-huannh
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update OrderController
parent
b51f5c0a
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
7 additions
and
36 deletions
+7
-36
OrderController.php
app/Http/Controllers/Api/OrderController.php
+2
-14
AuthController.php
app/Http/Controllers/AuthController.php
+0
-1
OrderController.php
app/Http/Controllers/OrderController.php
+0
-13
OrderRepository.php
app/Repositories/OrderRepository.php
+5
-7
api.php
routes/api.php
+0
-1
No files found.
app/Http/Controllers/Api/OrderController.php
View file @
2057d743
...
...
@@ -26,9 +26,9 @@ public function __construct(OrderRepository $orderRepository, UserRepository $us
public
function
index
(
Request
$request
)
{
$id
=
$request
->
id
;
$user
=
$this
->
userRepository
->
getByid
(
$id
)
;
$user
=
auth
(
'api'
)
->
user
()
->
id
;
if
(
$user
->
role
==
User
::
ROLE_ADMIN
)
{
$order
=
$this
->
orderRepository
->
paginate
(
$request
->
page
);
$order
=
$this
->
orderRepository
->
getListOrderOfAdmin
(
$request
);
}
elseif
(
$user
->
role
==
User
::
ROLE_EDITOR
)
{
$order
=
$this
->
orderRepository
->
getListOrderOfUser
(
$id
);
}
...
...
@@ -129,16 +129,4 @@ public function destroy(Request $request)
]);
}
public
function
search
(
Request
$request
)
{
$order
=
$this
->
orderRepository
->
getListOrderByStatus
(
$request
->
status
);
return
response
()
->
json
([
'success'
=>
true
,
'meta'
=>
[
'total'
=>
$order
->
total
(),
'pages'
=>
$order
->
lastPage
()
],
'data'
=>
OrderResource
::
collection
(
$order
)
]);
}
}
app/Http/Controllers/AuthController.php
View file @
2057d743
...
...
@@ -3,7 +3,6 @@
namespace
App\Http\Controllers
;
use
Illuminate\Http\Request
;
use
Illuminate\Support\Facades\Auth
;
use
App\Models\User
;
use
Validator
;
...
...
app/Http/Controllers/OrderController.php
View file @
2057d743
...
...
@@ -128,17 +128,4 @@ public function destroy(Request $request)
'data'
=>
$order
]);
}
public
function
search
(
Request
$request
)
{
$order
=
$this
->
orderRepository
->
getListOrderByStatus
(
$request
->
status
);
return
response
()
->
json
([
'success'
=>
true
,
'meta'
=>
[
'total'
=>
$order
->
total
(),
'pages'
=>
$order
->
lastPage
()
],
'data'
=>
OrderResource
::
collection
(
$order
)
]);
}
}
app/Repositories/OrderRepository.php
View file @
2057d743
...
...
@@ -4,6 +4,7 @@
use
App\Models\Order
;
use
App\Repositories\BaseRepository
;
use
Illuminate\Http\Request
;
class
OrderRepository
extends
BaseRepository
{
...
...
@@ -23,15 +24,12 @@ public function getFulfilledOrder()
$this
->
model
->
where
(
'is_fulfilled'
,
true
);
}
public
function
getListOrderOf
User
(
$id
)
public
function
getListOrderOf
Admin
(
Request
$request
)
{
return
$order
=
$this
->
model
->
with
(
'user'
)
->
whereHas
(
'user'
,
function
(
$query
)
use
(
$id
)
{
$query
->
where
(
'id'
,
$id
);
})
->
paginate
();
return
$this
->
model
->
latest
()
->
where
(
'status'
,
$request
->
status
)
->
paginate
();
}
public
function
getListOrderByStatus
(
$status
)
public
function
getListOrderOfUser
(
$id
)
{
return
$
order
=
$this
->
model
->
where
(
'status'
,
$status
)
->
paginate
();
return
$
this
->
model
->
where
(
'user_id'
,
$id
)
->
with
(
'user'
)
->
paginate
();
}
}
routes/api.php
View file @
2057d743
...
...
@@ -35,6 +35,5 @@
'middleware'
=>
'api'
,
],
function
(
$router
)
{
Route
::
get
(
'orders/search'
,
[
App\Http\Controllers\Api\OrderController
::
class
,
'search'
]);
Route
::
resource
(
'orders'
,
App\Http\Controllers\Api\OrderController
::
class
);
});
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