Fetch servers with product to reduce SQL-Queries
This commit is contained in:
parent
0f5369043d
commit
f6eab834fc
|
@ -233,14 +233,18 @@ 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
return number_format($usage, 2, '.', '');
|
return number_format($usage, 2, '.', '');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return array|string|string[]
|
* @return array|string|string[]
|
||||||
|
|
Loading…
Reference in a new issue