39 lines
1 KiB
PHP
39 lines
1 KiB
PHP
<?php
|
|
|
|
use App\Models\Word;
|
|
|
|
/*
|
|
|--------------------------------------------------------------------------
|
|
| Application Routes
|
|
|--------------------------------------------------------------------------
|
|
|
|
|
| Here is where you can register all of the routes for an application.
|
|
| It is a breeze. Simply tell Lumen the URIs it should respond to
|
|
| and give it the Closure to call when that URI is requested.
|
|
|
|
|
*/
|
|
|
|
$router->get('/', function() {
|
|
return redirect()->route('word', [ 'uuid' => Word::getRandom() ]);
|
|
});
|
|
|
|
$router->get('/{uuid}[/{guess}]', ['as' => 'word', function($uuid, $guess = false) {
|
|
|
|
$word = Word::where('uuid', $uuid)->first();
|
|
if (!$word) {
|
|
abort(404);
|
|
}
|
|
|
|
$params = [
|
|
'uuid' => $uuid,
|
|
'word' => $word->value
|
|
];
|
|
|
|
if ($guess !== false) {
|
|
$params['guess'] = $guess;
|
|
$params['correct'] = $guess === $word->type;
|
|
$params['next'] = Word::getRandom($uuid);
|
|
return view('result', $params);
|
|
}
|
|
return view('main', $params);
|
|
}]);
|