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' => 'Blog'];
@@ -1,3 +1,40 @@
<?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('blog_posts', function(Blueprint $table): void { $table->id(); $table->foreignId('author_id')->nullable()->constrained('authors')->nullOnDelete(); $table->foreignId('category_id')->nullable()->constrained('categories')->nullOnDelete(); $table->string('title'); $table->string('slug')->unique(); $table->text('excerpt')->nullable(); $table->longText('content')->nullable(); $table->string('featured_image')->nullable(); $table->string('status')->default('draft')->index(); $table->boolean('is_featured')->default(false); $table->timestamp('published_at')->nullable()->index(); $table->timestamp('expires_at')->nullable(); $table->string('meta_title')->nullable(); $table->text('meta_description')->nullable(); $table->timestamps(); }); Schema::create('blog_post_tag', function(Blueprint $table): void { $table->foreignId('blog_post_id')->constrained('blog_posts')->cascadeOnDelete(); $table->foreignId('tag_id')->constrained('tags')->cascadeOnDelete(); $table->primary(['blog_post_id','tag_id']); }); } public function down(): void { Schema::dropIfExists('blog_post_tag'); Schema::dropIfExists('blog_posts'); } };
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('blog_posts', function (Blueprint $table): void {
$table->id();
$table->foreignId('author_id')->nullable()->constrained('authors')->nullOnDelete();
$table->foreignId('category_id')->nullable()->constrained('categories')->nullOnDelete();
$table->string('title');
$table->string('slug')->unique();
$table->text('excerpt')->nullable();
$table->longText('content')->nullable();
$table->string('featured_image')->nullable();
$table->string('status')->default('draft')->index();
$table->boolean('is_featured')->default(false);
$table->timestamp('published_at')->nullable()->index();
$table->timestamp('expires_at')->nullable();
$table->string('meta_title')->nullable();
$table->text('meta_description')->nullable();
$table->timestamps();
});
Schema::create('blog_post_tag', function (Blueprint $table): void {
$table->foreignId('blog_post_id')->constrained('blog_posts')->cascadeOnDelete();
$table->foreignId('tag_id')->constrained('tags')->cascadeOnDelete();
$table->primary(['blog_post_id', 'tag_id']);
});
}
public function down(): void
{
Schema::dropIfExists('blog_post_tag');
Schema::dropIfExists('blog_posts');
}
};
@@ -1,4 +1,66 @@
<?php
namespace Modules\Blog\Http\Controllers;
use App\Http\Controllers\Controller; use Illuminate\Http\RedirectResponse; use Illuminate\Http\Request; use Illuminate\View\View; use Modules\Authors\Models\Author; use Modules\Categories\Models\Category; use Modules\Tags\Models\Tag; use Modules\Blog\Models\Blog;
final class BlogController extends Controller { public function index(): View { return view('blog::admin.index',['records'=>Blog::with(['author','category'])->latest()->paginate(25)]); } public function create(): View { return view('blog::admin.form',$this->lookups()); } public function store(Request $r): RedirectResponse { $record=Blog::create($this->data($r)); $record->tags()->sync($r->input('tag_ids',[])); return redirect()->route('administration.blog.index')->with('status','Blog created.'); } public function edit(Blog $blog_post): View { return view('blog::admin.form',array_merge($this->lookups(),['record'=>$blog_post])); } public function update(Request $r, Blog $blog_post): RedirectResponse { $blog_post->update($this->data($r)); $blog_post->tags()->sync($r->input('tag_ids',[])); return redirect()->route('administration.blog.index')->with('status','Blog updated.'); } public function destroy(Blog $blog_post): RedirectResponse { $blog_post->delete(); return back()->with('status','Blog deleted.'); } private function lookups(): array { return ['authors'=>Author::where('is_active',true)->orderBy('name')->get(),'categories'=>Category::where('is_active',true)->orderBy('name')->get(),'tags'=>Tag::orderBy('name')->get()]; } private function data(Request $r): array { $d=$r->validate(['author_id'=>['nullable','exists:authors,id'],'category_id'=>['nullable','exists:categories,id'],'title'=>['required','string','max:255'],'slug'=>['required','string','max:255'],'excerpt'=>['nullable','string'],'content'=>['nullable','string'],'featured_image'=>['nullable','string','max:255'],'status'=>['required','in:draft,review,published,archived'],'is_featured'=>['sometimes','boolean'],'published_at'=>['nullable','date'],'expires_at'=>['nullable','date','after:published_at'],'meta_title'=>['nullable','string','max:255'],'meta_description'=>['nullable','string']]); $d['is_featured']=$r->boolean('is_featured'); return $d; } }
use App\Http\Controllers\Controller;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\View\View;
use Modules\Authors\Models\Author;
use Modules\Blog\Models\Blog;
use Modules\Categories\Models\Category;
use Modules\Tags\Models\Tag;
final class BlogController extends Controller
{
public function index(): View
{
return view('blog::admin.index', ['records' => Blog::with(['author', 'category'])->latest()->paginate(25)]);
}
public function create(): View
{
return view('blog::admin.form', $this->lookups());
}
public function store(Request $r): RedirectResponse
{
$record = Blog::create($this->data($r));
$record->tags()->sync($r->input('tag_ids', []));
return redirect()->route('administration.blog.index')->with('status', 'Blog created.');
}
public function edit(Blog $blog_post): View
{
return view('blog::admin.form', array_merge($this->lookups(), ['record' => $blog_post]));
}
public function update(Request $r, Blog $blog_post): RedirectResponse
{
$blog_post->update($this->data($r));
$blog_post->tags()->sync($r->input('tag_ids', []));
return redirect()->route('administration.blog.index')->with('status', 'Blog updated.');
}
public function destroy(Blog $blog_post): RedirectResponse
{
$blog_post->delete();
return back()->with('status', 'Blog deleted.');
}
private function lookups(): array
{
return ['authors' => Author::where('is_active', true)->orderBy('name')->get(), 'categories' => Category::where('is_active', true)->orderBy('name')->get(), 'tags' => Tag::orderBy('name')->get()];
}
private function data(Request $r): array
{
$d = $r->validate(['author_id' => ['nullable', 'exists:authors,id'], 'category_id' => ['nullable', 'exists:categories,id'], 'title' => ['required', 'string', 'max:255'], 'slug' => ['required', 'string', 'max:255'], 'excerpt' => ['nullable', 'string'], 'content' => ['nullable', 'string'], 'featured_image' => ['nullable', 'string', 'max:255'], 'status' => ['required', 'in:draft,review,published,archived'], 'is_featured' => ['sometimes', 'boolean'], 'published_at' => ['nullable', 'date'], 'expires_at' => ['nullable', 'date', 'after:published_at'], 'meta_title' => ['nullable', 'string', 'max:255'], 'meta_description' => ['nullable', 'string']]);
$d['is_featured'] = $r->boolean('is_featured');
return $d;
}
}
@@ -1,3 +1,20 @@
<?php
namespace Modules\Blog\Http\Controllers; use App\Http\Controllers\Controller; use Illuminate\View\View; use Modules\Blog\Models\Blog;
final class PublicBlogController extends Controller { public function index(): View { return view('blog::public.index',['records'=>Blog::published()->with(['author','category'])->latest('published_at')->paginate(12)]); } public function show(string $slug): View { return view('blog::public.show',['record'=>Blog::published()->with(['author','category','tags'])->where('slug',$slug)->firstOrFail()]); } }
namespace Modules\Blog\Http\Controllers;
use App\Http\Controllers\Controller;
use Illuminate\View\View;
use Modules\Blog\Models\Blog;
final class PublicBlogController extends Controller
{
public function index(): View
{
return view('blog::public.index', ['records' => Blog::published()->with(['author', 'category'])->latest('published_at')->paginate(12)]);
}
public function show(string $slug): View
{
return view('blog::public.show', ['record' => Blog::published()->with(['author', 'category', 'tags'])->where('slug', $slug)->firstOrFail()]);
}
}
+45 -2
View File
@@ -1,5 +1,48 @@
<?php
namespace Modules\Blog\Models;
use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\Relations\BelongsToMany; use Modules\Authors\Models\Author; use Modules\Categories\Models\Category; use Modules\Tags\Models\Tag; use Modules\Workflow\Concerns\HasWorkflow; use Modules\Localization\Concerns\HasTranslations;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Modules\Authors\Models\Author;
use Modules\Categories\Models\Category;
use Modules\Localization\Concerns\HasTranslations;
use Modules\Sites\Concerns\BelongsToSites;
final class Blog extends Model { use BelongsToSites, HasTranslations, HasWorkflow; protected $table='blog_posts'; protected $fillable=['author_id','category_id','title','slug','excerpt','content','featured_image','status','is_featured','published_at','expires_at','meta_title','meta_description']; protected function casts(): array { return ['is_featured'=>'boolean','published_at'=>'datetime','expires_at'=>'datetime']; } public function author(): BelongsTo { return $this->belongsTo(Author::class); } public function category(): BelongsTo { return $this->belongsTo(Category::class); } public function tags(): BelongsToMany { return $this->belongsToMany(Tag::class, 'blog_post_tag'); } public function scopePublished(Builder $query): Builder { return $query->where('status','published')->where(fn(Builder $q)=>$q->whereNull('published_at')->orWhere('published_at','<=',now()))->where(fn(Builder $q)=>$q->whereNull('expires_at')->orWhere('expires_at','>',now())); } }
use Modules\Tags\Models\Tag;
use Modules\Workflow\Concerns\HasWorkflow;
final class Blog extends Model
{
use BelongsToSites, HasTranslations, HasWorkflow;
protected $table = 'blog_posts';
protected $fillable = ['author_id', 'category_id', 'title', 'slug', 'excerpt', 'content', 'featured_image', 'status', 'is_featured', 'published_at', 'expires_at', 'meta_title', 'meta_description'];
protected function casts(): array
{
return ['is_featured' => 'boolean', 'published_at' => 'datetime', 'expires_at' => 'datetime'];
}
public function author(): BelongsTo
{
return $this->belongsTo(Author::class);
}
public function category(): BelongsTo
{
return $this->belongsTo(Category::class);
}
public function tags(): BelongsToMany
{
return $this->belongsToMany(Tag::class, 'blog_post_tag');
}
public function scopePublished(Builder $query): Builder
{
return $query->where('status', 'published')->where(fn (Builder $q) => $q->whereNull('published_at')->orWhere('published_at', '<=', now()))->where(fn (Builder $q) => $q->whereNull('expires_at')->orWhere('expires_at', '>', now()));
}
}
@@ -1,6 +1,9 @@
<?php
namespace Modules\Blog\Providers;
use Illuminate\Support\ServiceProvider;
final class BlogServiceProvider extends ServiceProvider
{
public function register(): void
@@ -8,6 +11,7 @@ final class BlogServiceProvider extends ServiceProvider
$this->app->register(RouteServiceProvider::class);
$this->mergeConfigFrom(module_path('Blog', 'Config/config.php'), 'blog');
}
public function boot(): void
{
$this->loadMigrationsFrom(module_path('Blog', 'Database/Migrations'));
@@ -1,7 +1,10 @@
<?php
namespace Modules\Blog\Providers;
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
use Illuminate\Support\Facades\Route;
final class RouteServiceProvider extends ServiceProvider
{
public function boot(): void
+10 -3
View File
@@ -1,4 +1,11 @@
<?php
use Illuminate\Support\Facades\Route; use Modules\Blog\Http\Controllers\BlogController; use Modules\Blog\Http\Controllers\PublicBlogController;
Route::middleware(['auth','verified'])->prefix('administration/blog')->name('administration.blog.')->group(function (): void { Route::resource('/', BlogController::class)->parameters([''=>'blog_post'])->except('show'); });
Route::get('/blog',[PublicBlogController::class,'index'])->name('blog.public.index'); Route::get('/blog/{slug}',[PublicBlogController::class,'show'])->name('blog.public.show');
use Illuminate\Support\Facades\Route;
use Modules\Blog\Http\Controllers\BlogController;
use Modules\Blog\Http\Controllers\PublicBlogController;
Route::middleware(['auth', 'verified'])->prefix('administration/blog')->name('administration.blog.')->group(function (): void {
Route::resource('/', BlogController::class)->parameters(['' => 'blog_post'])->except('show');
});
Route::get('/blog', [PublicBlogController::class, 'index'])->name('blog.public.index');
Route::get('/blog/{slug}', [PublicBlogController::class, 'show'])->name('blog.public.show');