Add page showing all fetched articles

This commit is contained in:
myrmidex 2025-06-29 17:24:35 +02:00
parent 4162c23717
commit 527a55db57
3 changed files with 40 additions and 0 deletions

View file

@ -0,0 +1,17 @@
<?php
namespace App\Http\Controllers;
use App\Models\Article;
use Illuminate\Contracts\View\View;
use Illuminate\Http\Request;
class ArticlesController extends Controller
{
public function __invoke(Request $request): View
{
$articles = Article::all()->sortByDesc('created_at');
return view('articles.index', compact('articles'));
}
}

View file

@ -0,0 +1,20 @@
<h1>Articles</h1>
<table>
<thead>
<tr>
<th>ID</th>
<th>URL</th>
<th>Created At</th>
</tr>
</thead>
<tbody>
@foreach($articles as $article)
<tr>
<td>{{ $article->id }}</td>
<td>{{ $article->url }}</td>
<td>{{ $article->created_at->format('Y-m-d H:i') }}</td>
</tr>
@endforeach
</tbody>
</table>

View file

@ -1,5 +1,6 @@
<?php <?php
use App\Http\Controllers\ArticlesController;
use Illuminate\Support\Facades\Route; use Illuminate\Support\Facades\Route;
use Inertia\Inertia; use Inertia\Inertia;
@ -15,3 +16,5 @@
require __DIR__.'/settings.php'; require __DIR__.'/settings.php';
require __DIR__.'/auth.php'; require __DIR__.'/auth.php';
Route::get('/articles', ArticlesController::class)->name('articles');