public function bulk($ids, $action) { if (!$ids) { return 0; } $credits = Credit::withTrashed()->scope($ids)->get(); foreach ($credits as $credit) { if ($action == 'restore') { $credit->restore(); } else { if ($action == 'delete') { $credit->is_deleted = true; $credit->save(); } $credit->delete(); } } return count($credits); }
public function createNinjaCredit($client, $amount) { $account = $this->getNinjaAccount(); $lastCredit = Credit::withTrashed()->whereAccountId($account->id)->orderBy('public_id', 'DESC')->first(); $publicId = $lastCredit ? $lastCredit->public_id + 1 : 1; $credit = new Credit(); $credit->public_id = $publicId; $credit->account_id = $account->id; $credit->user_id = $account->users()->first()->id; $credit->client_id = $client->id; $credit->amount = $amount; $credit->save(); return $credit; }