style updates

This commit is contained in:
Mark Gregory
2026-07-24 14:59:44 +01:00
parent 24ab771cd3
commit dd23205d0b
482 changed files with 7173 additions and 1435 deletions
+1
View File
@@ -1,2 +1,3 @@
<?php
return ['name' => 'Comments'];
@@ -1,3 +1,31 @@
<?php
use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema;
return new class extends Migration { public function up(): void { Schema::create('comments', function(Blueprint $table): void { $table->id(); $table->nullableMorphs('commentable'); $table->foreignId('parent_id')->nullable()->constrained('comments')->cascadeOnDelete(); $table->foreignId('user_id')->nullable()->constrained()->nullOnDelete(); $table->string('author_name'); $table->string('author_email'); $table->text('body'); $table->string('status')->default('pending')->index(); $table->string('ip_address',45)->nullable(); $table->text('moderation_notes')->nullable(); $table->timestamp('approved_at')->nullable(); $table->timestamps(); }); } public function down(): void { Schema::dropIfExists('comments'); } };
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::create('comments', function (Blueprint $table): void {
$table->id();
$table->nullableMorphs('commentable');
$table->foreignId('parent_id')->nullable()->constrained('comments')->cascadeOnDelete();
$table->foreignId('user_id')->nullable()->constrained()->nullOnDelete();
$table->string('author_name');
$table->string('author_email');
$table->text('body');
$table->string('status')->default('pending')->index();
$table->string('ip_address', 45)->nullable();
$table->text('moderation_notes')->nullable();
$table->timestamp('approved_at')->nullable();
$table->timestamps();
});
}
public function down(): void
{
Schema::dropIfExists('comments');
}
};
@@ -1,3 +1,38 @@
<?php
namespace Modules\Comments\Http\Controllers; use App\Http\Controllers\Controller; use Illuminate\Http\RedirectResponse; use Illuminate\Http\Request; use Illuminate\View\View; use Modules\Comments\Models\Comment;
final class CommentController extends Controller { public function index(Request $r): View { $q=Comment::latest(); if($r->filled('status')) $q->where('status',$r->string('status')); return view('comments::admin.index',['records'=>$q->paginate(30)]); } public function update(Request $r, Comment $comment): RedirectResponse { $data=$r->validate(['status'=>['required','in:pending,approved,spam,rejected'],'moderation_notes'=>['nullable','string']]); $data['approved_at']=$data['status']==='approved' ? now() : null; $comment->update($data); return back()->with('status','Comment moderated.'); } public function destroy(Comment $comment): RedirectResponse { $comment->delete(); return back()->with('status','Comment deleted.'); } }
namespace Modules\Comments\Http\Controllers;
use App\Http\Controllers\Controller;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\View\View;
use Modules\Comments\Models\Comment;
final class CommentController extends Controller
{
public function index(Request $r): View
{
$q = Comment::latest();
if ($r->filled('status')) {
$q->where('status', $r->string('status'));
}
return view('comments::admin.index', ['records' => $q->paginate(30)]);
}
public function update(Request $r, Comment $comment): RedirectResponse
{
$data = $r->validate(['status' => ['required', 'in:pending,approved,spam,rejected'], 'moderation_notes' => ['nullable', 'string']]);
$data['approved_at'] = $data['status'] === 'approved' ? now() : null;
$comment->update($data);
return back()->with('status', 'Comment moderated.');
}
public function destroy(Comment $comment): RedirectResponse
{
$comment->delete();
return back()->with('status', 'Comment deleted.');
}
}
+20 -2
View File
@@ -1,3 +1,21 @@
<?php
namespace Modules\Comments\Models; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\MorphTo;
final class Comment extends Model { protected $fillable=['commentable_type','commentable_id','parent_id','user_id','author_name','author_email','body','status','ip_address','moderation_notes','approved_at']; protected function casts(): array { return ['approved_at'=>'datetime']; } public function commentable(): MorphTo { return $this->morphTo(); } }
namespace Modules\Comments\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\MorphTo;
final class Comment extends Model
{
protected $fillable = ['commentable_type', 'commentable_id', 'parent_id', 'user_id', 'author_name', 'author_email', 'body', 'status', 'ip_address', 'moderation_notes', 'approved_at'];
protected function casts(): array
{
return ['approved_at' => 'datetime'];
}
public function commentable(): MorphTo
{
return $this->morphTo();
}
}
@@ -1,6 +1,9 @@
<?php
namespace Modules\Comments\Providers;
use Illuminate\Support\ServiceProvider;
final class CommentsServiceProvider extends ServiceProvider
{
public function register(): void
@@ -8,6 +11,7 @@ final class CommentsServiceProvider extends ServiceProvider
$this->app->register(RouteServiceProvider::class);
$this->mergeConfigFrom(module_path('Comments', 'Config/config.php'), 'comments');
}
public function boot(): void
{
$this->loadMigrationsFrom(module_path('Comments', 'Database/Migrations'));
@@ -1,7 +1,10 @@
<?php
namespace Modules\Comments\Providers;
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
use Illuminate\Support\Facades\Route;
final class RouteServiceProvider extends ServiceProvider
{
public function boot(): void
+9 -2
View File
@@ -1,3 +1,10 @@
<?php
use Illuminate\Support\Facades\Route; use Modules\Comments\Http\Controllers\CommentController;
Route::middleware(['auth','verified'])->prefix('administration/comments')->name('administration.comments.')->group(function (): void { Route::get('/',[CommentController::class,'index'])->name('index'); Route::put('/{comment}',[CommentController::class,'update'])->name('update'); Route::delete('/{comment}',[CommentController::class,'destroy'])->name('destroy'); });
use Illuminate\Support\Facades\Route;
use Modules\Comments\Http\Controllers\CommentController;
Route::middleware(['auth', 'verified'])->prefix('administration/comments')->name('administration.comments.')->group(function (): void {
Route::get('/', [CommentController::class, 'index'])->name('index');
Route::put('/{comment}', [CommentController::class, 'update'])->name('update');
Route::delete('/{comment}', [CommentController::class, 'destroy'])->name('destroy');
});
@@ -1,6 +1,9 @@
<?php
namespace Modules\Comments\Tests\Feature;
use Tests\TestCase;
final class ModuleBootTest extends TestCase
{
public function test_module_configuration_is_available(): void