Implement projects and project keys

This commit is contained in:
2026-03-25 00:44:37 +01:00
parent aeee3d2640
commit 7d4b0733b3
16 changed files with 716 additions and 1 deletions
@@ -0,0 +1,40 @@
<?php
namespace App\Http\Controllers;
use App\Http\Requests\StoreProjectRequest;
use App\Models\Project;
use Illuminate\Http\RedirectResponse;
use Inertia\Inertia;
use Inertia\Response;
class ProjectController extends Controller
{
public function index(): Response
{
return Inertia::render('projects/Index', [
'projects' => Project::query()
->orderByDesc('id')
->get(),
]);
}
public function create(): Response
{
return Inertia::render('projects/Create');
}
public function store(StoreProjectRequest $request): RedirectResponse
{
$project = Project::query()->create($request->validated());
return to_route('projects.show', $project);
}
public function show(Project $project): Response
{
return Inertia::render('projects/Show', [
'project' => $project,
]);
}
}
+46
View File
@@ -0,0 +1,46 @@
<?php
namespace App\Http\Requests;
use Illuminate\Contracts\Validation\ValidationRule;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;
class StoreProjectRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*/
public function authorize(): bool
{
return $this->user() !== null;
}
protected function prepareForValidation(): void
{
if ($this->has('key')) {
$this->merge([
'key' => strtoupper((string) $this->string('key')->trim()),
]);
}
}
/**
* Get the validation rules that apply to the request.
*
* @return array<string, ValidationRule|array<mixed>|string>
*/
public function rules(): array
{
return [
'key' => [
'required',
'string',
'max:5',
'regex:/^[A-Z0-9]+$/',
Rule::unique('projects', 'key'),
],
'name' => ['required', 'string', 'max:255'],
];
}
}