diff --git a/app/Http/Controllers/ActivityController.php b/app/Http/Controllers/ActivityController.php
index 7233b638..e0b9c842 100644
--- a/app/Http/Controllers/ActivityController.php
+++ b/app/Http/Controllers/ActivityController.php
@@ -8,7 +8,9 @@ class ActivityController extends Controller
{
public function index()
{
- $activities = Activity::ofSpace(session('space_id'))->get();
+ $activities = Activity::query()
+ ->where('space_id', session('space_id'))
+ ->get();
return view('activities.index', ['activities' => $activities]);
}
diff --git a/app/Http/Controllers/Api/ActivitiesController.php b/app/Http/Controllers/Api/ActivitiesController.php
index ae114ba6..4ab8dcc3 100644
--- a/app/Http/Controllers/Api/ActivitiesController.php
+++ b/app/Http/Controllers/Api/ActivitiesController.php
@@ -14,7 +14,9 @@ public function __invoke(Request $request)
/** @var ApiKey $apiKey */
$apiKey = $request->get('apiKey');
- $activities = Activity::ofSpace($apiKey->user->spaces()->first()->id)->get();
+ $activities = Activity::query()
+ ->where('space_id', $apiKey->user->spaces()->first()->id)
+ ->get();
return ActivityResource::collection($activities);
}
diff --git a/app/Http/Controllers/BudgetController.php b/app/Http/Controllers/BudgetController.php
index 3a5a2476..d169827d 100644
--- a/app/Http/Controllers/BudgetController.php
+++ b/app/Http/Controllers/BudgetController.php
@@ -30,7 +30,10 @@ public function index()
public function create()
{
- $tags = Tag::ofSpace(session('space_id'))->latest()->get();
+ $tags = Tag::query()
+ ->where('space_id', session('space_id'))
+ ->latest()
+ ->get();
return view('budgets.create', ['tags' => $tags]);
}
diff --git a/app/Http/Controllers/ImportController.php b/app/Http/Controllers/ImportController.php
index f83b24f9..e2579680 100644
--- a/app/Http/Controllers/ImportController.php
+++ b/app/Http/Controllers/ImportController.php
@@ -21,7 +21,7 @@ public function __construct(SpendingRepository $spendingRepository)
public function index()
{
return view('imports.index')->with([
- 'imports' => Import::ofSpace(session('space_id'))->latest()->get()
+ 'imports' => Import::query()->where('space_id', session('space_id'))->latest()->get()
]);
}
@@ -97,7 +97,9 @@ public function getComplete(Import $import)
{
$this->authorize('modify', $import);
- $tags = Tag::ofSpace(session('space_id'))->get();
+ $tags = Tag::query()
+ ->where('space_id', session('space_id'))
+ ->get();
$file = fopen(storage_path('app/imports/' . $import->file), 'r');
diff --git a/app/Http/Controllers/RecurringController.php b/app/Http/Controllers/RecurringController.php
index e750f086..161a09aa 100644
--- a/app/Http/Controllers/RecurringController.php
+++ b/app/Http/Controllers/RecurringController.php
@@ -20,7 +20,10 @@ public function __construct(RecurringRepository $recurringRepository)
public function index()
{
- $recurrings = Recurring::ofSpace(session('space_id'))->latest()->get();
+ $recurrings = Recurring::query()
+ ->where('space_id', session('space_id'))
+ ->latest()
+ ->get();
return view('recurrings.index', ['recurrings' => $recurrings]);
}
@@ -36,7 +39,7 @@ public function create()
{
$tags = [];
- foreach (Tag::ofSpace(session('space_id'))->get() as $tag) {
+ foreach (Tag::query()->where('space_id', session('space_id'))->get() as $tag) {
$tags[] = ['key' => $tag->id, 'label' => $tag->name];
}
diff --git a/app/Http/Controllers/ReportController.php b/app/Http/Controllers/ReportController.php
index 22faa93f..fad9632b 100644
--- a/app/Http/Controllers/ReportController.php
+++ b/app/Http/Controllers/ReportController.php
@@ -33,7 +33,7 @@ private function weeklyReport($year)
private function mostExpensiveTags()
{
- $totalSpent = Spending::ofSpace(session('space_id'))->sum('amount');
+ $totalSpent = Spending::query()->where('space_id', session('space_id'))->sum('amount');
$mostExpensiveTags = $this->tagRepository->getMostExpensiveTags(session('space_id'));
return view('reports.most_expensive_tags', compact('totalSpent', 'mostExpensiveTags'));
diff --git a/app/Http/Controllers/SpendingController.php b/app/Http/Controllers/SpendingController.php
index cdf52a85..8045a12e 100644
--- a/app/Http/Controllers/SpendingController.php
+++ b/app/Http/Controllers/SpendingController.php
@@ -25,7 +25,10 @@ public function __construct(
public function create()
{
- $tags = Tag::ofSpace(session('space_id'))->latest()->get();
+ $tags = Tag::query()
+ ->where('space_id', session('space_id'))
+ ->latest()
+ ->get();
return view('spendings.create', ['tags' => $tags]);
}
@@ -71,7 +74,10 @@ public function edit(Spending $spending)
{
$this->authorize('edit', $spending);
- $tags = Tag::ofSpace(session('space_id'))->latest()->get();
+ $tags = Tag::query()
+ ->where('space_id', session('space_id'))
+ ->latest()
+ ->get();
return view('spendings.edit', compact('tags', 'spending'));
}
diff --git a/app/Http/Controllers/TagController.php b/app/Http/Controllers/TagController.php
index bb03c423..cf21f37a 100644
--- a/app/Http/Controllers/TagController.php
+++ b/app/Http/Controllers/TagController.php
@@ -17,7 +17,10 @@ public function __construct(TagRepository $tagRepository)
public function index()
{
- $tags = Tag::ofSpace(session('space_id'))->latest()->get();
+ $tags = Tag::query()
+ ->where('space_id', session('space_id'))
+ ->latest()
+ ->get();
return view('tags.index', ['tags' => $tags]);
}
diff --git a/app/Http/Controllers/TransactionController.php b/app/Http/Controllers/TransactionController.php
index d1d878c3..ca5a8333 100644
--- a/app/Http/Controllers/TransactionController.php
+++ b/app/Http/Controllers/TransactionController.php
@@ -35,7 +35,7 @@ public function index(Request $request)
return view('transactions.index', [
'yearMonths' => $this->repository->getTransactionsByYearMonth($filterBy),
- 'tags' => Tag::ofSpace(session('space_id'))->get()
+ 'tags' => Tag::query()->where('space_id', session('space_id'))->get(),
]);
}
@@ -43,7 +43,7 @@ public function create()
{
$tags = [];
- foreach (Tag::ofSpace(session('space_id'))->get() as $tag) {
+ foreach (Tag::query()->where('space_id', session('space_id'))->get() as $tag) {
$tags[] = [
'key' => $tag->id,
'label' => '
' // phpcs:ignore
diff --git a/app/Models/Activity.php b/app/Models/Activity.php
index 8432a530..8f238256 100644
--- a/app/Models/Activity.php
+++ b/app/Models/Activity.php
@@ -17,10 +17,4 @@ public function user()
{
return $this->belongsTo(User::class);
}
-
- // Scopes
- public function scopeOfSpace($query, $spaceId)
- {
- return $query->where('space_id', $spaceId);
- }
}
diff --git a/app/Models/Currency.php b/app/Models/Currency.php
index 34c9a281..6a74123d 100644
--- a/app/Models/Currency.php
+++ b/app/Models/Currency.php
@@ -21,10 +21,4 @@ protected function isoLowercased(): Attribute
{
return Attribute::make(fn () => strtolower($this->iso));
}
-
- // Scopes
- public function scopeOfSpace($query, $spaceId)
- {
- return $query->where('space_id', $spaceId);
- }
}
diff --git a/app/Models/Earning.php b/app/Models/Earning.php
index cec99160..d9762e57 100644
--- a/app/Models/Earning.php
+++ b/app/Models/Earning.php
@@ -46,10 +46,4 @@ public function attachments()
return $this->hasMany(Attachment::class, 'transaction_id')
->where('transaction_type', 'earning');
}
-
- // Scopes
- public function scopeOfSpace($query, $spaceId)
- {
- return $query->where('space_id', $spaceId);
- }
}
diff --git a/app/Models/Import.php b/app/Models/Import.php
index a2211175..c609b424 100644
--- a/app/Models/Import.php
+++ b/app/Models/Import.php
@@ -31,10 +31,4 @@ public function spendings()
{
return $this->hasMany(Spending::class);
}
-
- // Scopes
- public function scopeOfSpace($query, $spaceId)
- {
- return $query->where('space_id', $spaceId);
- }
}
diff --git a/app/Models/Recurring.php b/app/Models/Recurring.php
index b9d1e4fd..8eeff469 100644
--- a/app/Models/Recurring.php
+++ b/app/Models/Recurring.php
@@ -71,10 +71,4 @@ public function tag()
{
return $this->belongsTo(Tag::class);
}
-
- // Scopes
- public function scopeOfSpace($query, $spaceId)
- {
- return $query->where('space_id', $spaceId);
- }
}
diff --git a/app/Models/Spending.php b/app/Models/Spending.php
index 46c5da37..c637c208 100644
--- a/app/Models/Spending.php
+++ b/app/Models/Spending.php
@@ -63,10 +63,4 @@ public function attachments()
return $this->hasMany(Attachment::class, 'transaction_id')
->where('transaction_type', 'spending');
}
-
- // Scopes
- public function scopeOfSpace($query, $spaceId)
- {
- return $query->where('space_id', $spaceId);
- }
}
diff --git a/app/Models/Tag.php b/app/Models/Tag.php
index 0997557a..f46df41d 100644
--- a/app/Models/Tag.php
+++ b/app/Models/Tag.php
@@ -41,10 +41,4 @@ public static function randomColor()
{
return self::randomColorPart() . self::randomColorPart() . self::randomColorPart();
}
-
- // Scopes
- public function scopeOfSpace($query, $spaceId)
- {
- return $query->where('space_id', $spaceId);
- }
}
diff --git a/app/Repositories/DashboardRepository.php b/app/Repositories/DashboardRepository.php
index 1377f221..04a9e689 100644
--- a/app/Repositories/DashboardRepository.php
+++ b/app/Repositories/DashboardRepository.php
@@ -30,7 +30,8 @@ public function getLeftToSpend(string $year, string $month)
// TODO MOVE TO SPENDINGREPOSITORY IN FUTURE
public function getTotalAmountSpent(string $year, string $month)
{
- return Spending::ofSpace(session('space_id'))
+ return Spending::query()
+ ->where('space_id', session('space_id'))
->whereRaw('YEAR(happened_on) = ? AND MONTH(happened_on) = ?', [$year, $month])
->sum('amount');
}
@@ -43,11 +44,13 @@ public function getDailyBalance(int $spaceId, string $year, string $month): arra
$dailyBalance = [];
for ($i = 1; $i <= $daysInMonth; $i++) {
- $balanceTick -= Spending::ofSpace($spaceId)
+ $balanceTick -= Spending::query()
+ ->where('space_id', $spaceId)
->where('happened_on', $year . '-' . $month . '-' . $i)
->sum('amount');
- $balanceTick += Earning::ofSpace($spaceId)
+ $balanceTick += Earning::query()
+ ->where('space_id', $spaceId)
->where('happened_on', $year . '-' . $month . '-' . $i)
->sum('amount');
diff --git a/app/Repositories/TransactionRepository.php b/app/Repositories/TransactionRepository.php
index 62c6d6f2..0e083f73 100644
--- a/app/Repositories/TransactionRepository.php
+++ b/app/Repositories/TransactionRepository.php
@@ -21,11 +21,13 @@ public function getWeeklyBalance(string $year): array
}
for ($i = 1; $i <= 53; $i++) { // This used to be 52, IDK what happens after we moved it to 53
- $balance += Earning::ofSpace(session('space_id'))
+ $balance += Earning::query()
+ ->where('space_id', session('space_id'))
->whereRaw('YEAR(happened_on) = ? AND WEEK(happened_on, ?) = ?', [$year, $weekMode, $i])
->sum('amount');
- $balance -= Spending::ofSpace(session('space_id'))
+ $balance -= Spending::query()
+ ->where('space_id', session('space_id'))
->whereRaw('YEAR(happened_on) = ? AND WEEK(happened_on, ?) = ?', [$year, $weekMode, $i])
->sum('amount');
@@ -40,7 +42,7 @@ public function getTransactionsByYearMonth(array $filterBy = [])
$yearMonths = [];
// Populate yearMonths with earnings
- foreach (Earning::ofSpace(session('space_id'))->get() as $earning) {
+ foreach (Earning::query()->where('space_id', session('space_id'))->get() as $earning) {
$shouldAdd = false;
if (!$filterBy) {
@@ -59,7 +61,7 @@ public function getTransactionsByYearMonth(array $filterBy = [])
}
// Populate yearMonths with spendings
- foreach (Spending::ofSpace(session('space_id'))->get() as $spending) {
+ foreach (Spending::query()->where('space_id', session('space_id'))->get() as $spending) {
$shouldAdd = true;
// Filter
diff --git a/app/Widgets/Spent.php b/app/Widgets/Spent.php
index b0f5f734..b3cd78a5 100644
--- a/app/Widgets/Spent.php
+++ b/app/Widgets/Spent.php
@@ -22,7 +22,8 @@ public function render()
$currencySymbol = $space->currency->symbol;
if ($this->properties->period === 'today') {
- $spent = Spending::ofSpace(session('space_id'))
+ $spent = Spending::query()
+ ->where('space_id', session('space_id'))
->whereRaw('DATE(happened_on) = ?', [date('Y-m-d')])
->sum('amount');
}
@@ -31,13 +32,15 @@ public function render()
$monday = date('Y-m-d', strtotime('monday this week'));
$sunday = date('Y-m-d', strtotime('sunday this week'));
- $spent = Spending::ofSpace(session('space_id'))
+ $spent = Spending::query()
+ ->where('space_id', session('space_id'))
->whereRaw('DATE(happened_on) >= ? AND DATE(happened_ON) <= ?', [$monday, $sunday])
->sum('amount');
}
if ($this->properties->period === 'this_month') {
- $spent = Spending::ofSpace(session('space_id'))
+ $spent = Spending::query()
+ ->where('space_id', session('space_id'))
->whereRaw('YEAR(happened_on) = ? AND MONTH(happened_on) = ?', [date('Y'), date('n')])
->sum('amount');
}