Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Sign in / Register
Toggle navigation
T
test-webshop
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
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
Artem
test-webshop
Commits
833c0e38
Commit
833c0e38
authored
May 15, 2020
by
Artem
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
make eager loading on orders page and reduce db queries in cart model by updating current items
parent
e52ef3b4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
30 additions
and
4 deletions
+30
-4
Cart.php
app/Cart.php
+12
-1
ProfileController.php
app/Http/Controllers/ProfileController.php
+5
-1
AppServiceProvider.php
app/Providers/AppServiceProvider.php
+13
-1
orders.blade.php
resources/views/profile/orders.blade.php
+0
-1
No files found.
app/Cart.php
View file @
833c0e38
...
...
@@ -67,9 +67,20 @@ class Cart /*extends Model*/
public
function
updateCurrentItems
()
{
// foreach ($this->items as $id => $item) {
// $this->items[$id]['item'] = Product::where('id', $id)->first();
// }
// TODO ask if this is good solution for perfromance improvement
$productsIdArr
=
[];
foreach
(
$this
->
items
as
$id
=>
$item
)
{
$
this
->
items
[
$id
][
'item'
]
=
Product
::
where
(
'id'
,
$id
)
->
first
()
;
$
productsIdArr
[]
=
$id
;
}
$products
=
Product
::
whereIn
(
'id'
,
$productsIdArr
)
->
get
();
foreach
(
$products
as
$product
)
{
$this
->
items
[
$product
->
id
][
'item'
]
=
$product
;
}
$this
->
updateTotalPrice
();
}
}
app/Http/Controllers/ProfileController.php
View file @
833c0e38
...
...
@@ -14,7 +14,11 @@ class ProfileController extends Controller
public
function
showOrders
()
{
$orders
=
Auth
::
user
()
->
orders
()
->
orderBy
(
'id'
,
'desc'
)
->
paginate
(
10
);
$orders
=
Auth
::
user
()
->
orders
()
->
with
(
'products'
)
// TODO ask if this is correct use
->
orderBy
(
'id'
,
'desc'
)
->
paginate
(
10
);
return
view
(
'profile.orders'
,
compact
(
'orders'
));
}
...
...
app/Providers/AppServiceProvider.php
View file @
833c0e38
...
...
@@ -23,6 +23,18 @@ class AppServiceProvider extends ServiceProvider
*/
public
function
boot
()
{
//
// \Event::listen('Illuminate\Database\Events\QueryExecuted', function ($query) {
//// dump($query->sql);
//// dump($query->bindings);
//// dump($query->time);
// });
// \DB::listen(function($query) {
// \Log::info(
//// $query->sql,
//// $query->bindings,
// $query->time
// );
// });
}
}
resources/views/profile/orders.blade.php
View file @
833c0e38
...
...
@@ -23,7 +23,6 @@
@foreach(
$order->products
as
$product
)
<li class="
list
-
group
-
item
order
-
item
">
<a href="
{{
route
(
'product.show'
,
$product
->
product_id
)
}}
"
{{-- href="
{{
$product
->
product
->
path
()
}}
" TODO ask if this is good for performance, to get product from eloquent relation --}}
>{{
$product->ordered_reference
}}</a>
<div class="
d
-
flex
">
<div>{{
$product->ordered_price
}} EUR</div>
...
...
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