Fetch servers with product to reduce SQL-Queries
This commit is contained in:
parent
0f5369043d
commit
f6eab834fc
1 changed files with 7 additions and 3 deletions
|
@ -233,14 +233,18 @@ class User extends Authenticatable implements MustVerifyEmail
|
|||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
return number_format($usage, 2, '.', '');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array|string|string[]
|
||||
|
|
Loading…
Add table
Reference in a new issue