#4-merge-with-master-conflict-resolve
This commit is contained in:
43
app/Http/Requests/StoreCategoryRequest.php
Normal file
43
app/Http/Requests/StoreCategoryRequest.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use Illuminate\Contracts\Validation\ValidationRule;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class StoreCategoryRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare the data for validation.
|
||||
*/
|
||||
protected function prepareForValidation(): void
|
||||
{
|
||||
$this->merge([
|
||||
'slug' => Str::slug((string) ($this->filled('slug') ? $this->input('slug') : $this->input('name'))),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array<string, ValidationRule|array<mixed>|string>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'name' => ['required', 'string', 'max:255', 'unique:categories,name'],
|
||||
'slug' => ['required', 'string', 'max:255', 'alpha_dash:ascii', 'unique:categories,slug'],
|
||||
'description' => ['nullable', 'string', 'max:1000'],
|
||||
'color' => ['required', 'string', 'regex:/^#[0-9A-Fa-f]{6}$/'],
|
||||
];
|
||||
}
|
||||
}
|
||||
46
app/Http/Requests/UpdateCategoryRequest.php
Normal file
46
app/Http/Requests/UpdateCategoryRequest.php
Normal file
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use Illuminate\Contracts\Validation\ValidationRule;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class UpdateCategoryRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare the data for validation.
|
||||
*/
|
||||
protected function prepareForValidation(): void
|
||||
{
|
||||
$this->merge([
|
||||
'slug' => Str::slug((string) ($this->filled('slug') ? $this->input('slug') : $this->input('name'))),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array<string, ValidationRule|array<mixed>|string>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
$categoryId = $this->route('category')?->id;
|
||||
|
||||
return [
|
||||
'name' => ['required', 'string', 'max:255', Rule::unique('categories', 'name')->ignore($categoryId)],
|
||||
'slug' => ['required', 'string', 'max:255', 'alpha_dash:ascii', Rule::unique('categories', 'slug')->ignore($categoryId)],
|
||||
'description' => ['nullable', 'string', 'max:1000'],
|
||||
'color' => ['required', 'string', 'regex:/^#[0-9A-Fa-f]{6}$/'],
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user