phase two updates
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
<?php
|
||||
|
||||
return ['name' => 'Documents'];
|
||||
@@ -0,0 +1,15 @@
|
||||
<?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('documents', function (Blueprint $table): void { $table->id();
|
||||
$table->string('title');
|
||||
$table->text('description')->nullable();
|
||||
$table->string('file_path')->nullable();
|
||||
$table->boolean('is_public')->default(true);
|
||||
$table->timestamps(); $table->softDeletes(); }); }
|
||||
public function down(): void { Schema::dropIfExists('documents'); }
|
||||
};
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Documents\Http\Controllers;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\View\View;
|
||||
use Modules\Documents\Models\Document;
|
||||
|
||||
final class DocumentController extends Controller
|
||||
{
|
||||
public function index(): View { return view('documents::admin.index', ['records' => Document::query()->latest()->paginate(20)]); }
|
||||
public function create(): View { return view('documents::admin.form'); }
|
||||
public function store(Request $request): RedirectResponse { $data = $request->validate(['title' => ['required', 'string', 'max:255'],
|
||||
'description' => ['nullable', 'string'],
|
||||
'file_path' => ['nullable', 'string'],
|
||||
'is_public' => ['sometimes', 'boolean']]); $data['is_public'] = $request->boolean('is_public'); Document::create($data); return redirect()->route('documents.index')->with('status', 'Document created.'); }
|
||||
public function edit(Document $document): View { return view('documents::admin.form', ['record' => $document]); }
|
||||
public function update(Request $request, Document $document): RedirectResponse { $data = $request->validate(['title' => ['required', 'string', 'max:255'],
|
||||
'description' => ['nullable', 'string'],
|
||||
'file_path' => ['nullable', 'string'],
|
||||
'is_public' => ['sometimes', 'boolean']]); $data['is_public'] = $request->boolean('is_public'); $document->update($data); return redirect()->route('documents.index')->with('status', 'Document updated.'); }
|
||||
public function destroy(Document $document): RedirectResponse { $document->delete(); return back()->with('status', 'Document deleted.'); }
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Documents\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
final class Document extends Model
|
||||
{
|
||||
use HasFactory, SoftDeletes;
|
||||
protected $table = 'documents';
|
||||
protected $fillable = ['title', 'description', 'file_path', 'is_public'];
|
||||
|
||||
protected function casts(): array { return [
|
||||
'is_public' => 'boolean'
|
||||
]; }
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Documents\Providers;
|
||||
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
|
||||
final class DocumentsServiceProvider extends ServiceProvider
|
||||
{
|
||||
public function register(): void
|
||||
{
|
||||
$this->app->register(RouteServiceProvider::class);
|
||||
$this->mergeConfigFrom(module_path('Documents', 'Config/config.php'), 'documents');
|
||||
}
|
||||
|
||||
public function boot(): void
|
||||
{
|
||||
$this->loadMigrationsFrom(module_path('Documents', 'Database/Migrations'));
|
||||
$this->loadViewsFrom(module_path('Documents', 'Resources/views'), 'documents');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Documents\Providers;
|
||||
|
||||
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
|
||||
final class RouteServiceProvider extends ServiceProvider
|
||||
{
|
||||
public function boot(): void
|
||||
{
|
||||
parent::boot();
|
||||
$this->routes(fn () => Route::middleware('web')->group(module_path('Documents', 'Routes/web.php')));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
<x-layouts.app :title="isset($record) ? __('Edit Document') : __('Create Document')">
|
||||
<div class="mx-auto max-w-4xl space-y-6"><div><h1 class="text-2xl font-semibold">{{ isset($record) ? 'Edit' : 'Create' }} Document</h1></div><form method="POST" action="{{ isset($record) ? route('administration.documents.update', $record) : route('administration.documents.store') }}" class="space-y-5 rounded-xl border border-zinc-200 bg-white p-6 dark:border-zinc-700 dark:bg-zinc-900">@csrf @isset($record) @method('PUT') @endisset
|
||||
<div><label class="mb-1 block text-sm font-medium">Title</label><input type="text" name="title" value="{{ old('title', $record->title ?? '') }}" class="w-full rounded-lg border-zinc-300 dark:border-zinc-700 dark:bg-zinc-900">@error('title')<p class="text-sm text-red-600">{{ $message }}</p>@enderror</div>
|
||||
<div><label class="mb-1 block text-sm font-medium">Description</label><textarea name="description" rows="4" class="w-full rounded-lg border-zinc-300 dark:border-zinc-700 dark:bg-zinc-900">{{ old('description', $record->description ?? '') }}</textarea>@error('description')<p class="text-sm text-red-600">{{ $message }}</p>@enderror</div>
|
||||
<div><label class="mb-1 block text-sm font-medium">File Path</label><input type="text" name="file_path" value="{{ old('file_path', $record->file_path ?? '') }}" class="w-full rounded-lg border-zinc-300 dark:border-zinc-700 dark:bg-zinc-900">@error('file_path')<p class="text-sm text-red-600">{{ $message }}</p>@enderror</div>
|
||||
<label class="flex items-center gap-2"><input type="checkbox" name="is_public" value="1" @checked(old('is_public', $record->is_public ?? true))><span>Is Public</span></label>
|
||||
<div class="flex gap-3"><button class="rounded-lg bg-zinc-900 px-4 py-2 text-white dark:bg-white dark:text-zinc-900">Save</button><a href="{{ route('administration.documents.index') }}" class="rounded-lg border px-4 py-2">Cancel</a></div></form></div>
|
||||
</x-layouts.app>
|
||||
@@ -0,0 +1,5 @@
|
||||
<x-layouts.app :title="__('Documents')">
|
||||
<div class="space-y-6"><div class="flex items-center justify-between"><div><h1 class="text-2xl font-semibold">Documents</h1><p class="text-sm text-zinc-500">Manage documents content.</p></div><a href="{{ route('administration.documents.create') }}" class="rounded-lg bg-zinc-900 px-4 py-2 text-sm text-white dark:bg-white dark:text-zinc-900">Add new</a></div>
|
||||
@if(session('status'))<div class="rounded-lg bg-emerald-50 p-3 text-emerald-800">{{ session('status') }}</div>@endif
|
||||
<div class="overflow-hidden rounded-xl border border-zinc-200 bg-white dark:border-zinc-700 dark:bg-zinc-900"><table class="w-full text-sm"><thead class="bg-zinc-50 dark:bg-zinc-800"><tr><th class="px-4 py-3 text-left">Title</th><th class="px-4 py-3 text-left">Description</th><th class="px-4 py-3 text-left">File Path</th><th class="px-4 py-3 text-right">Actions</th></tr></thead><tbody class="divide-y divide-zinc-200 dark:divide-zinc-800">@forelse($records as $record)<tr><td class="px-4 py-3">{{ is_array($record->title) ? json_encode($record->title) : Str::limit((string) $record->title, 70) }}</td><td class="px-4 py-3">{{ is_array($record->description) ? json_encode($record->description) : Str::limit((string) $record->description, 70) }}</td><td class="px-4 py-3">{{ is_array($record->file_path) ? json_encode($record->file_path) : Str::limit((string) $record->file_path, 70) }}</td><td class="px-4 py-3 text-right"><a class="mr-3 underline" href="{{ route('administration.documents.edit', $record) }}">Edit</a><form class="inline" method="POST" action="{{ route('administration.documents.destroy', $record) }}">@csrf @method('DELETE')<button class="text-red-600" onclick="return confirm('Delete this record?')">Delete</button></form></td></tr>@empty<tr><td colspan="4" class="px-4 py-10 text-center text-zinc-500">No records yet.</td></tr>@endforelse</tbody></table></div>{{ $records->links() }}</div>
|
||||
</x-layouts.app>
|
||||
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Route;
|
||||
use Modules\Documents\Http\Controllers\DocumentController;
|
||||
|
||||
Route::middleware(['auth', 'verified'])->prefix('administration/documents')->name('administration.documents.')->group(function (): void {
|
||||
Route::resource('/', DocumentController::class)->parameters(['' => 'document'])->except('show');
|
||||
});
|
||||
@@ -0,0 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Documents\Support;
|
||||
|
||||
final class ModuleInfo { public static function name(): string { return 'Documents'; } public static function nameLower(): string { return 'documents'; } }
|
||||
@@ -0,0 +1,5 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Route;
|
||||
|
||||
it('registers the Documents administration route', function (): void { expect(Route::has('administration.documents.index'))->toBeTrue(); });
|
||||
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"name": "Documents",
|
||||
"alias": "documents",
|
||||
"version": "1.0.0",
|
||||
"description": "Documents CMS module.",
|
||||
"keywords": [
|
||||
"cms",
|
||||
"documents"
|
||||
],
|
||||
"priority": 25,
|
||||
"providers": [
|
||||
"Modules\\Documents\\Providers\\DocumentsServiceProvider"
|
||||
],
|
||||
"aliases": {},
|
||||
"files": [],
|
||||
"requires": [
|
||||
"Core",
|
||||
"Administration"
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user