phase two updates
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
<?php
|
||||
|
||||
return ['name' => 'Team'];
|
||||
@@ -0,0 +1,17 @@
|
||||
<?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('team_members', function (Blueprint $table): void { $table->id();
|
||||
$table->string('name');
|
||||
$table->string('job_title')->nullable();
|
||||
$table->text('biography')->nullable();
|
||||
$table->string('email')->nullable();
|
||||
$table->unsignedInteger('sort_order')->default(0);
|
||||
$table->boolean('enabled')->default(true);
|
||||
$table->timestamps(); $table->softDeletes(); }); }
|
||||
public function down(): void { Schema::dropIfExists('team_members'); }
|
||||
};
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Team\Http\Controllers;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\View\View;
|
||||
use Modules\Team\Models\TeamMember;
|
||||
|
||||
final class TeamMemberController extends Controller
|
||||
{
|
||||
public function index(): View { return view('team::admin.index', ['records' => TeamMember::query()->latest()->paginate(20)]); }
|
||||
public function create(): View { return view('team::admin.form'); }
|
||||
public function store(Request $request): RedirectResponse { $data = $request->validate(['name' => ['required', 'string', 'max:255'],
|
||||
'job_title' => ['nullable', 'string'],
|
||||
'biography' => ['nullable', 'string'],
|
||||
'email' => ['nullable', 'string'],
|
||||
'sort_order' => ['nullable', 'integer', 'min:0'],
|
||||
'enabled' => ['sometimes', 'boolean']]); $data['enabled'] = $request->boolean('enabled'); TeamMember::create($data); return redirect()->route('team.index')->with('status', 'TeamMember created.'); }
|
||||
public function edit(TeamMember $teamMember): View { return view('team::admin.form', ['record' => $teamMember]); }
|
||||
public function update(Request $request, TeamMember $teamMember): RedirectResponse { $data = $request->validate(['name' => ['required', 'string', 'max:255'],
|
||||
'job_title' => ['nullable', 'string'],
|
||||
'biography' => ['nullable', 'string'],
|
||||
'email' => ['nullable', 'string'],
|
||||
'sort_order' => ['nullable', 'integer', 'min:0'],
|
||||
'enabled' => ['sometimes', 'boolean']]); $data['enabled'] = $request->boolean('enabled'); $teamMember->update($data); return redirect()->route('team.index')->with('status', 'TeamMember updated.'); }
|
||||
public function destroy(TeamMember $teamMember): RedirectResponse { $teamMember->delete(); return back()->with('status', 'TeamMember deleted.'); }
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Team\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
final class TeamMember extends Model
|
||||
{
|
||||
use HasFactory, SoftDeletes;
|
||||
protected $table = 'team_members';
|
||||
protected $fillable = ['name', 'job_title', 'biography', 'email', 'sort_order', 'enabled'];
|
||||
|
||||
protected function casts(): array { return [
|
||||
'sort_order' => 'integer',
|
||||
'enabled' => 'boolean'
|
||||
]; }
|
||||
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Team\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('Team', 'Routes/web.php')));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Team\Providers;
|
||||
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
|
||||
final class TeamServiceProvider extends ServiceProvider
|
||||
{
|
||||
public function register(): void
|
||||
{
|
||||
$this->app->register(RouteServiceProvider::class);
|
||||
$this->mergeConfigFrom(module_path('Team', 'Config/config.php'), 'team');
|
||||
}
|
||||
|
||||
public function boot(): void
|
||||
{
|
||||
$this->loadMigrationsFrom(module_path('Team', 'Database/Migrations'));
|
||||
$this->loadViewsFrom(module_path('Team', 'Resources/views'), 'team');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
<x-layouts.app :title="isset($record) ? __('Edit TeamMember') : __('Create TeamMember')">
|
||||
<div class="mx-auto max-w-4xl space-y-6"><div><h1 class="text-2xl font-semibold">{{ isset($record) ? 'Edit' : 'Create' }} Team member</h1></div><form method="POST" action="{{ isset($record) ? route('administration.team.update', $record) : route('administration.team.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">Name</label><input type="text" name="name" value="{{ old('name', $record->name ?? '') }}" class="w-full rounded-lg border-zinc-300 dark:border-zinc-700 dark:bg-zinc-900">@error('name')<p class="text-sm text-red-600">{{ $message }}</p>@enderror</div>
|
||||
<div><label class="mb-1 block text-sm font-medium">Job Title</label><input type="text" name="job_title" value="{{ old('job_title', $record->job_title ?? '') }}" class="w-full rounded-lg border-zinc-300 dark:border-zinc-700 dark:bg-zinc-900">@error('job_title')<p class="text-sm text-red-600">{{ $message }}</p>@enderror</div>
|
||||
<div><label class="mb-1 block text-sm font-medium">Biography</label><textarea name="biography" rows="4" class="w-full rounded-lg border-zinc-300 dark:border-zinc-700 dark:bg-zinc-900">{{ old('biography', $record->biography ?? '') }}</textarea>@error('biography')<p class="text-sm text-red-600">{{ $message }}</p>@enderror</div>
|
||||
<div><label class="mb-1 block text-sm font-medium">Email</label><input type="text" name="email" value="{{ old('email', $record->email ?? '') }}" class="w-full rounded-lg border-zinc-300 dark:border-zinc-700 dark:bg-zinc-900">@error('email')<p class="text-sm text-red-600">{{ $message }}</p>@enderror</div>
|
||||
<div><label class="mb-1 block text-sm font-medium">Sort Order</label><input type="number" name="sort_order" value="{{ old('sort_order', $record->sort_order ?? '') }}" class="w-full rounded-lg border-zinc-300 dark:border-zinc-700 dark:bg-zinc-900">@error('sort_order')<p class="text-sm text-red-600">{{ $message }}</p>@enderror</div>
|
||||
<label class="flex items-center gap-2"><input type="checkbox" name="enabled" value="1" @checked(old('enabled', $record->enabled ?? true))><span>Enabled</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.team.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="__('Team')">
|
||||
<div class="space-y-6"><div class="flex items-center justify-between"><div><h1 class="text-2xl font-semibold">Team</h1><p class="text-sm text-zinc-500">Manage team content.</p></div><a href="{{ route('administration.team.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">Name</th><th class="px-4 py-3 text-left">Job Title</th><th class="px-4 py-3 text-left">Biography</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->name) ? json_encode($record->name) : Str::limit((string) $record->name, 70) }}</td><td class="px-4 py-3">{{ is_array($record->job_title) ? json_encode($record->job_title) : Str::limit((string) $record->job_title, 70) }}</td><td class="px-4 py-3">{{ is_array($record->biography) ? json_encode($record->biography) : Str::limit((string) $record->biography, 70) }}</td><td class="px-4 py-3 text-right"><a class="mr-3 underline" href="{{ route('administration.team.edit', $record) }}">Edit</a><form class="inline" method="POST" action="{{ route('administration.team.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\Team\Http\Controllers\TeamMemberController;
|
||||
|
||||
Route::middleware(['auth', 'verified'])->prefix('administration/team')->name('administration.team.')->group(function (): void {
|
||||
Route::resource('/', TeamMemberController::class)->parameters(['' => 'teamMember'])->except('show');
|
||||
});
|
||||
@@ -0,0 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Team\Support;
|
||||
|
||||
final class ModuleInfo { public static function name(): string { return 'Team'; } public static function nameLower(): string { return 'team'; } }
|
||||
@@ -0,0 +1,5 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Route;
|
||||
|
||||
it('registers the Team administration route', function (): void { expect(Route::has('administration.team.index'))->toBeTrue(); });
|
||||
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"name": "Team",
|
||||
"alias": "team",
|
||||
"version": "1.0.0",
|
||||
"description": "Team CMS module.",
|
||||
"keywords": [
|
||||
"cms",
|
||||
"team"
|
||||
],
|
||||
"priority": 28,
|
||||
"providers": [
|
||||
"Modules\\Team\\Providers\\TeamServiceProvider"
|
||||
],
|
||||
"aliases": {},
|
||||
"files": [],
|
||||
"requires": [
|
||||
"Core",
|
||||
"Administration"
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user