Add page showing all fetched articles
This commit is contained in:
parent
4162c23717
commit
527a55db57
3 changed files with 40 additions and 0 deletions
17
app/Http/Controllers/ArticlesController.php
Normal file
17
app/Http/Controllers/ArticlesController.php
Normal 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'));
|
||||||
|
}
|
||||||
|
}
|
||||||
20
resources/views/articles/index.blade.php
Normal file
20
resources/views/articles/index.blade.php
Normal 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>
|
||||||
|
|
@ -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');
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue