Bring search functionality back to life
MODIFY
app/Http/Controllers/SearchController.php
app/Http/Controllers/SearchController.php
@@ -9,16 +9,20 @@ use App\Spending;
class SearchController extends Controller {
public function index(Request $request) {
- $data = [];
+ $user = \Auth::user();
- if ($request->has('query')) {
- $data['query'] = $request->get('query');
+ $currency = $user->currency;
+
+ $earnings = [];
- $data['earnings'] = Earning::where('description', 'like', '%' . $request->get('query') . '%')->get();
+ $spendings = [];
+
+ if ($request->has('query')) {
+ $earnings = Earning::where('description', 'like', '%' . $request->get('query') . '%')->get();
- $data['spendings'] = Spending::where('description', 'like', '%' . $request->get('query') . '%')->get();
+ $spendings = Spending::where('description', 'like', '%' . $request->get('query') . '%')->get();
}
- return view('search.index', $data);
+ return view('search.index', compact('currency', 'earnings', 'spendings'));
}
}

MODIFY
resources/views/search/index.blade.php
resources/views/search/index.blade.php
<div class="section">
<div class="row">
<div class="column align-middle">
- <h3>Search</h3>
+ <span class="color-dark">Search</span>
</div>
<div class="column">
<form method="GET">
</div>
</div>
</div>
- <div class="section">Search is temporarily out of order</div>
+ @if (count($earnings))
+ <ul class="section">
+ @foreach ($earnings as $earning)
+ <li>
+ <div class="row">
+ <div class="column">
+ <p class="spacing-bottom-small">{{ $earning->description }}</p>
+ <p>{{ date('jS', strtotime($earning->date)) }}</p>
+ </div>
+ <div class="column text-align-right align-middle">
+ <h3>{{ $currency->symbol }} {{ $earning->amount }}</h3>
+ </div>
+ </div>
+ </li>
+ @endforeach
+ </ul>
+ @endif
+ @if (count($spendings))
+ <ul class="section">
+ @foreach ($spendings as $spending)
+ <li>
+ <div class="row">
+ <div class="column">
+ <p class="spacing-bottom-small">{{ $spending->description }}</p>
+ <p>{{ $spending->tag->name }} &middot; {{ date('F jS, Y', strtotime($spending->date)) }}</p>
+ </div>
+ <div class="column text-align-right align-middle">
+ <h3>{{ $currency->symbol }} {{ $spending->amount }}</h3>
+ </div>
+ </div>
+ </li>
+ @endforeach
+ </ul>
+ @endif
</div>
</div>
@endsection

Bring search functionality back to life