word-salad/routes/web.php

41 lines
1.2 KiB
PHP

<?php
use App\Models\Article;
use Illuminate\Support\Facades\Route;
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider and all of them will
| be assigned to the "web" middleware group. Make something great!
|
*/
Route::get('/', function () {
return view('guest.home');
});
Route::get('/test-insert', function () {
return view('test-insert');
})->name('test-insert');
Route::get('/recent-articles', function () {
$all_articles = Article::where('published_at', '<', now())->limit(10)->get();
return view('guest.all-articles', ['all_articles' => $all_articles]);
})->name('recent-articles');
Route::get('/post/{article_slug}', function ($article_slug) {
$active_article = Article::with('author')
->where('published_at', '<', now())
->where('slug', $article_slug)
->first();
if(empty($active_article)) {
return abort(404);
}
return view('guest.article', ['article' => $active_article]);
})->name('article');