Switch bio to be stored in database
This commit is contained in:
parent
f51a740858
commit
bdb69df52d
14 changed files with 219 additions and 38 deletions
32
app/Http/Controllers/Admin/BioController.php
Normal file
32
app/Http/Controllers/Admin/BioController.php
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Http\Controllers\Admin;
|
||||||
|
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use App\Models\Bio;
|
||||||
|
use Illuminate\Http\RedirectResponse;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\View\View;
|
||||||
|
|
||||||
|
class BioController extends Controller
|
||||||
|
{
|
||||||
|
public function show(): View
|
||||||
|
{
|
||||||
|
$bio = Bio::first();
|
||||||
|
|
||||||
|
return view('admin.bio.show', [
|
||||||
|
'bioEntry' => $bio,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function update(Request $request): RedirectResponse
|
||||||
|
{
|
||||||
|
$bio = Bio::firstOrNew();
|
||||||
|
$bio->content = $request->input('content');
|
||||||
|
$bio->save();
|
||||||
|
|
||||||
|
return redirect()->route('admin.bio.show');
|
||||||
|
}
|
||||||
|
}
|
|
@ -3,6 +3,7 @@
|
||||||
namespace App\Http\Controllers;
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
use App\Models\Article;
|
use App\Models\Article;
|
||||||
|
use App\Models\Bio;
|
||||||
use App\Models\Bookmark;
|
use App\Models\Bookmark;
|
||||||
use App\Models\Like;
|
use App\Models\Like;
|
||||||
use App\Models\Note;
|
use App\Models\Note;
|
||||||
|
@ -34,8 +35,11 @@ class FrontPageController extends Controller
|
||||||
->sortByDesc('updated_at')
|
->sortByDesc('updated_at')
|
||||||
->paginate(10);
|
->paginate(10);
|
||||||
|
|
||||||
|
$bio = Bio::first()?->content;
|
||||||
|
|
||||||
return view('front-page', [
|
return view('front-page', [
|
||||||
'items' => $items,
|
'items' => $items,
|
||||||
|
'bio' => $bio,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
11
app/Models/Bio.php
Normal file
11
app/Models/Bio.php
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
|
class Bio extends Model
|
||||||
|
{
|
||||||
|
use HasFactory;
|
||||||
|
}
|
23
database/factories/BioFactory.php
Normal file
23
database/factories/BioFactory.php
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Database\Factories;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Bio>
|
||||||
|
*/
|
||||||
|
class BioFactory extends Factory
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Define the model's default state.
|
||||||
|
*
|
||||||
|
* @return array<string, mixed>
|
||||||
|
*/
|
||||||
|
public function definition(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'content' => $this->faker->paragraph,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
28
database/migrations/2023_04_11_115837_create_bios_table.php
Normal file
28
database/migrations/2023_04_11_115837_create_bios_table.php
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*/
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
Schema::create('bios', function (Blueprint $table) {
|
||||||
|
$table->id();
|
||||||
|
$table->text('content');
|
||||||
|
$table->timestamps();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*/
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::dropIfExists('bios');
|
||||||
|
}
|
||||||
|
};
|
17
database/seeders/BioSeeder.php
Normal file
17
database/seeders/BioSeeder.php
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Database\Seeders;
|
||||||
|
|
||||||
|
use App\Models\Bio;
|
||||||
|
use Illuminate\Database\Seeder;
|
||||||
|
|
||||||
|
class BioSeeder extends Seeder
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the database seeds.
|
||||||
|
*/
|
||||||
|
public function run(): void
|
||||||
|
{
|
||||||
|
Bio::factory()->create();
|
||||||
|
}
|
||||||
|
}
|
19
resources/views/admin/bio/show.blade.php
Normal file
19
resources/views/admin/bio/show.blade.php
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
@extends('master')
|
||||||
|
|
||||||
|
@section('title')Edit Bio « Admin CP « @stop
|
||||||
|
|
||||||
|
@section('content')
|
||||||
|
<h1>Edit bio</h1>
|
||||||
|
<form action="/admin/bio" method="post" accept-charset="utf-8" class="admin-form form">
|
||||||
|
{{ csrf_field() }}
|
||||||
|
{{ method_field('PUT') }}
|
||||||
|
<div>
|
||||||
|
<label for="content">Content:</label>
|
||||||
|
<br>
|
||||||
|
<textarea name="content" id="content" rows="10" cols="50">{{ old('content', $bioEntry?->content) }}</textarea>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<button type="submit" name="save">Save</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
@stop
|
|
@ -46,4 +46,9 @@
|
||||||
You can either <a href="/admin/syndication/create">create</a> new syndication targets,
|
You can either <a href="/admin/syndication/create">create</a> new syndication targets,
|
||||||
or <a href="/admin/syndication">edit</a> them.
|
or <a href="/admin/syndication">edit</a> them.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
|
<h2>Bio</h2>
|
||||||
|
<p>
|
||||||
|
Edit your <a href="/admin/bio">bio</a>.
|
||||||
|
</p>
|
||||||
@stop
|
@stop
|
||||||
|
|
|
@ -27,6 +27,4 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{{ $items->links('templates.pagination') }}
|
{{ $items->links('templates.pagination') }}
|
||||||
|
|
||||||
@include('templates.bio')
|
|
||||||
@stop
|
@stop
|
||||||
|
|
|
@ -43,9 +43,11 @@
|
||||||
</header>
|
</header>
|
||||||
|
|
||||||
<main>
|
<main>
|
||||||
@yield('content')
|
@yield('content')
|
||||||
@section('bio')
|
|
||||||
@show
|
@isset($bio)
|
||||||
|
{!! $bio !!}
|
||||||
|
@endisset
|
||||||
</main>
|
</main>
|
||||||
|
|
||||||
<footer>
|
<footer>
|
||||||
|
|
|
@ -1,32 +0,0 @@
|
||||||
@section('bio')
|
|
||||||
<div class="h-card personal-bio">
|
|
||||||
<p>My name is <span class="p-name p-author">Jonny Barnes</span>, and
|
|
||||||
<a rel="me" href="https://jonnybarnes.uk" class="u-url">
|
|
||||||
<code>jonnybarnes.uk</code>
|
|
||||||
</a> is my site. I’m from
|
|
||||||
<a href="https://en.wikipedia.org/wiki/Manchester" class="h-adr p-adr">
|
|
||||||
<span class="p-locality">Manchester</span>,
|
|
||||||
<abbr class="p-country-name" title="United Kingdom">UK</abbr>
|
|
||||||
</a>.</p>
|
|
||||||
<p>I am active to varying degrees on several
|
|
||||||
<a href="https://indieweb.org/silo">silos</a>:</p>
|
|
||||||
<ul>
|
|
||||||
<li>I keep in touch with friends on <a rel="me" href="https://www.facebook.com/jonnybarnes" class="u-url">Facebook</a></li>
|
|
||||||
<li>I follow people I find interesting on <a rel="me" href="https://twitter.com/jonnybarnes" class="u-url">Twitter</a></li>
|
|
||||||
<li>I toot on the fediverse with my own instance of <a rel="me" href="https://mastodon.thebeeches.house/@jonny" class="u-url">Mastodon</a></li>
|
|
||||||
<li>I push code to <a rel="me" href="https://github.com/jonnybarnes" class="u-url">GitHub</a></li>
|
|
||||||
<li>I scrobble songs to <a rel="me" href="https://last.fm/user/jonnymbarnes" class="u-url">last.fm</a> that I listen to on <a rel="me" href="https://open.spotify.com/user/jonnybarnes89" class="u-url">Spotify</a> or <a rel="me" href="https://music.apple.com/profile/jonnybarnes" class="u-url">Apple Music</a></li>
|
|
||||||
<li>I post photos to <a rel="me" href="https://www.instagram.com/jonnybarnes/" class="u-url">Instagram</a></li>
|
|
||||||
</ul>
|
|
||||||
<p>My usual online nickname is normally <code class="nickname">
|
|
||||||
jonnybarnes</code> for other services. I also syndicate my content
|
|
||||||
to the IndieWeb friendly site
|
|
||||||
<a rel="me" href="https://micro.blog/jonnybarnes" class="u-url">micro.blog</a>.
|
|
||||||
Here’s a <a href="/assets/img/jmb-bw.png" class="u-photo photo">
|
|
||||||
profile pic</a>. I also have a
|
|
||||||
<a class="pgpkey" href="/assets/jonnybarnes-public-key-ecc.asc">PGP
|
|
||||||
key</a>, with <a href="/notes/5g">fingerprint</a>. You can email me
|
|
||||||
at jonny at my domain, or message me on
|
|
||||||
<a href="xmpp:jonny@chat.jonnybarnes.uk">XMPP</a>.</p>
|
|
||||||
</div>
|
|
||||||
@stop
|
|
|
@ -12,6 +12,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
use App\Http\Controllers\Admin\ArticlesController as AdminArticlesController;
|
use App\Http\Controllers\Admin\ArticlesController as AdminArticlesController;
|
||||||
|
use App\Http\Controllers\Admin\BioController;
|
||||||
use App\Http\Controllers\Admin\ClientsController;
|
use App\Http\Controllers\Admin\ClientsController;
|
||||||
use App\Http\Controllers\Admin\ContactsController as AdminContactsController;
|
use App\Http\Controllers\Admin\ContactsController as AdminContactsController;
|
||||||
use App\Http\Controllers\Admin\HomeController;
|
use App\Http\Controllers\Admin\HomeController;
|
||||||
|
@ -133,6 +134,12 @@ Route::group(['domain' => config('url.longurl')], function () {
|
||||||
Route::put('/{syndicationTarget}', [SyndicationTargetsController::class, 'update']);
|
Route::put('/{syndicationTarget}', [SyndicationTargetsController::class, 'update']);
|
||||||
Route::delete('/{syndicationTarget}', [SyndicationTargetsController::class, 'destroy']);
|
Route::delete('/{syndicationTarget}', [SyndicationTargetsController::class, 'destroy']);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Bio
|
||||||
|
Route::group(['prefix' => 'bio'], function () {
|
||||||
|
Route::get('/', [BioController::class, 'show'])->name('admin.bio.show');
|
||||||
|
Route::put('/', [BioController::class, 'update']);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// Blog pages using ArticlesController
|
// Blog pages using ArticlesController
|
||||||
|
|
67
tests/Feature/Admin/BioTest.php
Normal file
67
tests/Feature/Admin/BioTest.php
Normal file
|
@ -0,0 +1,67 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Tests\Feature\Admin;
|
||||||
|
|
||||||
|
use App\Models\Bio;
|
||||||
|
use App\Models\User;
|
||||||
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||||
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
class BioTest extends TestCase
|
||||||
|
{
|
||||||
|
use RefreshDatabase;
|
||||||
|
|
||||||
|
/** @test */
|
||||||
|
public function adminBiosPageLoads(): void
|
||||||
|
{
|
||||||
|
$user = User::factory()->make();
|
||||||
|
|
||||||
|
$response = $this->actingAs($user)
|
||||||
|
->get('/admin/bio');
|
||||||
|
$response->assertSeeText('Edit bio');
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @test */
|
||||||
|
public function adminCanCreateBio(): void
|
||||||
|
{
|
||||||
|
$user = User::factory()->make();
|
||||||
|
|
||||||
|
$this->actingAs($user)
|
||||||
|
->post('/admin/bio', [
|
||||||
|
'_method' => 'PUT',
|
||||||
|
'content' => 'Bio content',
|
||||||
|
]);
|
||||||
|
$this->assertDatabaseHas('bios', ['content' => 'Bio content']);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @test */
|
||||||
|
public function adminCanLoadExistingBio(): void
|
||||||
|
{
|
||||||
|
$user = User::factory()->make();
|
||||||
|
$bio = Bio::factory()->create([
|
||||||
|
'content' => 'This is <em>my</em> bio. It uses <strong>HTML</strong>.',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$response = $this->actingAs($user)
|
||||||
|
->get('/admin/bio');
|
||||||
|
$response->assertSeeText('This is <em>my</em> bio. It uses <strong>HTML</strong>.');
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @test */
|
||||||
|
public function adminCanEditBio(): void
|
||||||
|
{
|
||||||
|
$user = User::factory()->make();
|
||||||
|
$bio = Bio::factory()->create();
|
||||||
|
|
||||||
|
$this->actingAs($user)
|
||||||
|
->post('/admin/bio', [
|
||||||
|
'_method' => 'PUT',
|
||||||
|
'content' => 'This bio has been edited',
|
||||||
|
]);
|
||||||
|
$this->assertDatabaseHas('bios', [
|
||||||
|
'content' => 'This bio has been edited',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
|
@ -412,7 +412,7 @@ class NotesTest extends TestCase
|
||||||
'in_reply_to' => 'https://twitter.com/someRando/status/933662564587855877',
|
'in_reply_to' => 'https://twitter.com/someRando/status/933662564587855877',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$this->assertSame($tempContent, $note->twitter);
|
$this->assertEquals($tempContent, $note->twitter);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @test */
|
/** @test */
|
||||||
|
|
Loading…
Add table
Reference in a new issue