2024-02-04 23:36:46 +00:00
|
|
|
<?php
|
|
|
|
|
|
2024-08-04 04:50:42 +00:00
|
|
|
use App\Models\Article;
|
2024-02-04 23:36:46 +00:00
|
|
|
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 () {
|
2024-08-04 19:07:03 +00:00
|
|
|
return view('guest.home');
|
2024-02-04 23:36:46 +00:00
|
|
|
});
|
2024-08-04 04:50:42 +00:00
|
|
|
|
|
|
|
|
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();
|
2024-08-04 19:07:03 +00:00
|
|
|
return view('guest.all-articles', ['all_articles' => $all_articles]);
|
2024-08-04 04:50:42 +00:00
|
|
|
})->name('recent-articles');
|
2024-08-04 19:07:03 +00:00
|
|
|
|
|
|
|
|
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');
|