Add reusable project templates
This commit is contained in:
@@ -49,7 +49,7 @@ class StoreProjectRequest extends FormRequest
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'creation_mode' => ['required', 'string', Rule::in(['scratch', 'duplicate'])],
|
||||
'creation_mode' => ['required', 'string', Rule::in(['scratch', 'duplicate', 'template'])],
|
||||
'key' => [
|
||||
'required',
|
||||
'string',
|
||||
@@ -81,6 +81,12 @@ class StoreProjectRequest extends FormRequest
|
||||
}
|
||||
},
|
||||
],
|
||||
'source_template_id' => [
|
||||
Rule::requiredIf(fn (): bool => $this->input('creation_mode') === 'template'),
|
||||
'nullable',
|
||||
'integer',
|
||||
Rule::exists('project_templates', 'id'),
|
||||
],
|
||||
'copy_areas' => ['nullable', 'array'],
|
||||
'copy_areas.*' => [
|
||||
'string',
|
||||
@@ -96,6 +102,7 @@ class StoreProjectRequest extends FormRequest
|
||||
{
|
||||
return [
|
||||
'source_project_id.required' => 'Select a source project to duplicate from.',
|
||||
'source_template_id.required' => 'Select a template to create the project from.',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use App\Actions\Projects\DuplicateProjectConfiguration;
|
||||
use Illuminate\Contracts\Validation\ValidationRule;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class StoreProjectTemplateRequest extends FormRequest
|
||||
{
|
||||
public function authorize(): bool
|
||||
{
|
||||
return $this->user()?->can('create-project') ?? false;
|
||||
}
|
||||
|
||||
protected function prepareForValidation(): void
|
||||
{
|
||||
if ($this->filled('slug')) {
|
||||
$this->merge([
|
||||
'slug' => Str::slug((string) $this->input('slug')),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, ValidationRule|array<mixed>|string>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'name' => ['required', 'string', 'max:255'],
|
||||
'slug' => ['required', 'string', 'max:255', 'alpha_dash', Rule::unique('project_templates', 'slug')],
|
||||
'copy_areas' => ['required', 'array', 'min:1'],
|
||||
'copy_areas.*' => ['string', Rule::in(DuplicateProjectConfiguration::copyableAreas())],
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user