summaryrefslogtreecommitdiff
path: root/routes/web.php
blob: 0cd534f1f5920860cbc174f159b881f6d8771109 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?php

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/

use Illuminate\Http\Request;

/**
 * Display all quotes
 */
Route::get('/', function () {
    $quotes = \App\Quote::orderBy('created_at', 'asc')->get();

    return view('quotes', [
        'quotes' => $quotes
    ]);
});

/**
 * Add a new quote
 */
Route::post('/quote', function (Request $request) {
    $validator = Validator::make($request->all(), [
        'quote' => 'required|max:1023',
        'quotist' => 'required|max:63',
    ]);

    if ($validator->fails()) {
        return redirect('/')
            ->withInput()
            ->withErrors($validator);
    }

    $quote = new \App\Quote;
    $quote->quote = $request->quote;
    $quote->quotist = $request->quotist;
    $quote->save();

    return redirect('/');
});