Fetch servers with product to reduce SQL-Queries
This commit is contained in:
parent
0f5369043d
commit
f6eab834fc
|
@ -233,9 +233,13 @@ class User extends Authenticatable implements MustVerifyEmail
|
||||||
*/
|
*/
|
||||||
public function creditUsage()
|
public function creditUsage()
|
||||||
{
|
{
|
||||||
$usage = 0;
|
$servers = Server::query()
|
||||||
|
->where('user_id', '=', $this->id)
|
||||||
|
->with('product')
|
||||||
|
->get();
|
||||||
|
|
||||||
foreach ($this->Servers as $server) {
|
$usage = 0;
|
||||||
|
foreach ($servers as $server) {
|
||||||
$usage += $server->product->price;
|
$usage += $server->product->price;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue