Add message to search for when nothing could be found with query
MODIFY
app/Http/Controllers/SearchController.php
app/Http/Controllers/SearchController.php
@@ -13,16 +13,18 @@ class SearchController extends Controller {
$currency = $user->currency;
+ $query = $request->get('query');
+
$earnings = [];
$spendings = [];
if ($request->has('query')) {
- $earnings = Earning::where('description', 'like', '%' . $request->get('query') . '%')->get();
+ $earnings = Earning::where('description', 'like', '%' . $query . '%')->get();
- $spendings = Spending::where('description', 'like', '%' . $request->get('query') . '%')->get();
+ $spendings = Spending::where('description', 'like', '%' . $query . '%')->get();
}
- return view('search.index', compact('currency', 'earnings', 'spendings'));
+ return view('search.index', compact('currency', 'query', 'earnings', 'spendings'));
}
}

MODIFY
resources/views/search/index.blade.php
resources/views/search/index.blade.php
</div>
</div>
</div>
+ @if (!is_null($query) && !count($earnings) && !count($spendings))
+ <div class="section">There were no earnings/spendings found with that search query</div>
+ @endif
@if (count($earnings))
<ul class="section">
@foreach ($earnings as $earning)

Add message to search for when nothing could be found with query