mirror of
https://github.com/rico-vz/HeimerdingerLoL.git
synced 2025-12-06 10:10:48 +01:00
feat: Add PostsController and configure routes
- Added a new file `PostsController.php` in the `app/Http/Controllers` directory.
- Implemented the `index()` method to retrieve all posts using the Sheets facade.
- Implemented the `show()` method to display a single post using route model binding with Sheets.
- Updated the `RouteServiceProvider.php` file to bind the 'post' route parameter to retrieve posts from the Sheets collection.
- Created a new configuration file `sheets.php` in the `config` directory, defining default settings for collections and their corresponding sheet classes, path parsers, content parsers, and extensions.
- Added a new markdown file `hello-world.md` in the `content/posts` directory as an example post.
- Created two new blade view files: `index.blade.php` and `show.blade.php`, under the `resources/views/posts` directory, for displaying lists of posts and individual post details respectively.
- Modified the existing web routes (`web.php`) to include routes for accessing posts.
The changes enable users to view all posts on `/posts`, as well as access individual post details at `/post/{post}`.
This commit is contained in:
22
app/Http/Controllers/PostsController.php
Normal file
22
app/Http/Controllers/PostsController.php
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
|
use Spatie\Sheets\Facades\Sheets;
|
||||||
|
use Spatie\Sheets\Sheet;
|
||||||
|
|
||||||
|
class PostsController extends Controller
|
||||||
|
{
|
||||||
|
public function index()
|
||||||
|
{
|
||||||
|
$posts = Sheets::all();
|
||||||
|
|
||||||
|
return view('posts.index', compact('posts'));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function show(Sheet $post)
|
||||||
|
{
|
||||||
|
dd($post);
|
||||||
|
return view('posts.show', compact('post'));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -7,6 +7,7 @@ use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvi
|
|||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Support\Facades\RateLimiter;
|
use Illuminate\Support\Facades\RateLimiter;
|
||||||
use Illuminate\Support\Facades\Route;
|
use Illuminate\Support\Facades\Route;
|
||||||
|
use Spatie\Sheets\Sheets;
|
||||||
|
|
||||||
class RouteServiceProvider extends ServiceProvider
|
class RouteServiceProvider extends ServiceProvider
|
||||||
{
|
{
|
||||||
@@ -24,6 +25,8 @@ class RouteServiceProvider extends ServiceProvider
|
|||||||
*/
|
*/
|
||||||
public function boot(): void
|
public function boot(): void
|
||||||
{
|
{
|
||||||
|
parent::boot();
|
||||||
|
|
||||||
RateLimiter::for('api', function (Request $request) {
|
RateLimiter::for('api', function (Request $request) {
|
||||||
return Limit::perMinute(60)->by($request->user()?->id ?: $request->ip());
|
return Limit::perMinute(60)->by($request->user()?->id ?: $request->ip());
|
||||||
});
|
});
|
||||||
@@ -36,5 +39,11 @@ class RouteServiceProvider extends ServiceProvider
|
|||||||
Route::middleware('web')
|
Route::middleware('web')
|
||||||
->group(base_path('routes/web.php'));
|
->group(base_path('routes/web.php'));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Route::bind('post', function ($path) {
|
||||||
|
return $this->app->make(Sheets::class)
|
||||||
|
->collection('posts')
|
||||||
|
->get($path) ?? abort(404);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -56,6 +56,11 @@ return [
|
|||||||
'throw' => false,
|
'throw' => false,
|
||||||
],
|
],
|
||||||
|
|
||||||
|
'posts' => [
|
||||||
|
'driver' => 'local',
|
||||||
|
'root' => base_path('content/posts'),
|
||||||
|
]
|
||||||
|
|
||||||
],
|
],
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
14
config/sheets.php
Normal file
14
config/sheets.php
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
return [
|
||||||
|
'default_collection' => 'posts',
|
||||||
|
|
||||||
|
'collections' => [
|
||||||
|
'posts' => [
|
||||||
|
'sheet_class' => Spatie\Sheets\Sheet::class,
|
||||||
|
'path_parser' => Spatie\Sheets\PathParsers\SlugParser::class,
|
||||||
|
'content_parser' => Spatie\Sheets\ContentParsers\MarkdownWithFrontMatterParser::class,
|
||||||
|
'extension' => 'md',
|
||||||
|
]
|
||||||
|
],
|
||||||
|
];
|
||||||
9
content/posts/hello-world.md
Normal file
9
content/posts/hello-world.md
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
---
|
||||||
|
title: Hello, world!
|
||||||
|
description: Welcome to Sheets!
|
||||||
|
date: 2020-07-01
|
||||||
|
---
|
||||||
|
|
||||||
|
# Hello, world!
|
||||||
|
|
||||||
|
Welcome to Sheets!
|
||||||
20
resources/views/posts/index.blade.php
Normal file
20
resources/views/posts/index.blade.php
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
@extends('layouts.app')
|
||||||
|
|
||||||
|
@section('title', 'Heimerdinger.LoL • Posts')
|
||||||
|
@section('description', 'Explore all champion skins on Heimerdinger.LoL. Find detailed information on popular skins
|
||||||
|
such as Dark Cosmic Jhin, HEARTSTEEL Ezreal, PROJECT: Vayne and more!')
|
||||||
|
|
||||||
|
@section('content')
|
||||||
|
<section class="max-w-screen-xl mx-auto mt-12">
|
||||||
|
<h1
|
||||||
|
class="text-3xl font-bold text-center text-transparent uppercase sm:text-4xl
|
||||||
|
bg-gradient-to-bl from-orange-300 to-orange-500 bg-clip-text">
|
||||||
|
Posts</h1>
|
||||||
|
<h2 class="text-center text-orange-400 text-sm uppercase font-medium">Latest posts about League of Legends</h2>
|
||||||
|
@foreach($posts as $post)
|
||||||
|
{{ $post->title }}
|
||||||
|
{{ $post->description}}
|
||||||
|
|
||||||
|
@endforeach
|
||||||
|
</section>
|
||||||
|
@endsection
|
||||||
0
resources/views/posts/show.blade.php
Normal file
0
resources/views/posts/show.blade.php
Normal file
@@ -4,6 +4,7 @@ use App\Http\Controllers\AboutController;
|
|||||||
use App\Http\Controllers\AssetsController;
|
use App\Http\Controllers\AssetsController;
|
||||||
use App\Http\Controllers\ChampionController;
|
use App\Http\Controllers\ChampionController;
|
||||||
use App\Http\Controllers\FAQController;
|
use App\Http\Controllers\FAQController;
|
||||||
|
use App\Http\Controllers\PostsController;
|
||||||
use App\Http\Controllers\SaleController;
|
use App\Http\Controllers\SaleController;
|
||||||
use App\Http\Controllers\SummonerEmoteController;
|
use App\Http\Controllers\SummonerEmoteController;
|
||||||
use Illuminate\Support\Facades\Route;
|
use Illuminate\Support\Facades\Route;
|
||||||
@@ -76,6 +77,17 @@ Route::get('/about/faq/heimerdinger', [
|
|||||||
'heimerdinger'
|
'heimerdinger'
|
||||||
])->name('about.faq.heimerdinger');
|
])->name('about.faq.heimerdinger');
|
||||||
|
|
||||||
|
// Posts
|
||||||
|
Route::get('/posts', [
|
||||||
|
PostsController::class,
|
||||||
|
'index'
|
||||||
|
])->name('posts.index');
|
||||||
|
|
||||||
|
Route::get('/post/{post}', [
|
||||||
|
PostsController::class,
|
||||||
|
'show'
|
||||||
|
])->name('posts.show');
|
||||||
|
|
||||||
// Pulse
|
// Pulse
|
||||||
Route::get(config('app.login_route'), function () {
|
Route::get(config('app.login_route'), function () {
|
||||||
return redirect('/pulse');
|
return redirect('/pulse');
|
||||||
|
|||||||
Reference in New Issue
Block a user