Add SearchController
ADD
app/Http/Controllers/SearchController.php
+<?php
+
+namespace App\Http\Controllers;
+
+use Illuminate\Http\Request;
+
+use App\Earning;
+use App\Spending;
+
+class SearchController extends Controller {
+ public function index(Request $request) {
+ $data = [];
+
+ if ($request->has('query')) {
+ $data['query'] = $request->get('query');
+
+ $data['earnings'] = Earning::where('description', 'like', '%' . $request->get('query') . '%')->get();
+
+ $data['spendings'] = Spending::where('description', 'like', '%' . $request->get('query') . '%')->get();
+ }
+
+ return view('search.index', $data);
+ }
+}

MODIFY
public/style.css
public/style.css
@@ -28,7 +28,7 @@ a:hover {
color: #4880FE;
}
-body, h1, h2 {
+body, h1, h2, th {
font-weight: 400;
}
@@ -234,9 +234,14 @@ form.test input[type=submit]:hover {
table {
width: 100%;
border-collapse: collapse;
+ text-align: left;
}
-table td {
+table th {
+ color: #333;
+}
+
+table th, table td {
padding: 32px;
}

MODIFY
resources/views/layout.blade.php
resources/views/layout.blade.php
<li>
<a href="/dashboard">Dashboard</a>
</li>
+ <li>
+ <a href="/search">Search</a>
+ </li>
<li>
<a href="/reports">Reports</a>
</li>

ADD
resources/views/search/index.blade.php
+@extends('layout')
+
+@section('body')
+ <h1>Search</h1>
+ <form method="GET">
+ <div class="row spacing-top-large spacing-bottom-large">
+ <div class="column">
+ <input type="text" name="query" />
+ </div>
+ <div class="column">
+ <input type="submit" value="Search" />
+ </div>
+ </div>
+ </form>
+ @if (!empty($query))
+ <table class="box">
+ <thead>
+ <tr>
+ <th>Type</th>
+ <th>Description</th>
+ </tr>
+ </thread>
+ <tbody>
+ @foreach ($earnings as $earning)
+ <tr>
+ <td>Earning</td>
+ <td>{{ $earning->description }}</td>
+ </tr>
+ @endforeach
+ @foreach ($spendings as $spending)
+ <tr>
+ <td>Spending</td>
+ <td>{{ $spending->description }}</td>
+ </tr>
+ @endforeach
+ </tbody>
+ </table>
+ @endif
+@endsection

MODIFY
routes/web.php
routes/web.php
@@ -9,6 +9,8 @@ Route::post('/register', 'RegisterController@store');
Route::group(['middleware' => ['auth']], function () {
Route::get('/dashboard', 'DashboardController@index')->name('dashboard.index');
+ Route::get('/search', 'SearchController@index');
+
Route::resource('/earnings', 'EarningsController', ['only' => ['index', 'create', 'store', 'destroy']]);
Route::resource('/spendings', 'SpendingsController', ['only' => ['index', 'create', 'store', 'destroy']]);

Add SearchController