Enforce that filterBy parameter in getTransactionsByYearMonth method is an array and check if filters are provided before trying to access them
MODIFY
app/Http/Controllers/TransactionController.php
app/Http/Controllers/TransactionController.php
@@ -11,7 +11,7 @@ class TransactionController extends Controller {
}
public function index(Request $request) {
- $filterBy = null;
+ $filterBy = [];
if ($request->get('filterBy')) {
$filterBy = explode('-', $request->get('filterBy'));

MODIFY
app/Repositories/TransactionRepository.php
app/Repositories/TransactionRepository.php
@@ -5,7 +5,7 @@ namespace App\Repositories;
use Carbon\Carbon;
class TransactionRepository {
- public function getTransactionsByYearMonth($filterBy = null) {
+ public function getTransactionsByYearMonth(array $filterBy = []) {
$yearMonths = [];
// Populate yearMonths with earnings
@@ -32,11 +32,13 @@ class TransactionRepository {
$shouldAdd = true;
// Filter
+ if (count($filterBy)) { // Check if any filters were provided
if ($filterBy[0] == 'tag') {
if (!$spending->tag || $spending->tag->id != $filterBy[1]) {
$shouldAdd = false;
}
}
+ }
if ($shouldAdd) {
$i = Carbon::parse($spending->happened_on)->format('Y-m');

Enforce that filterBy parameter in getTransactionsByYearMonth method is an array and check if filters are provided before trying to access them