2017-11-04 17:06:14 -07:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Requests;
|
|
|
|
|
|
|
|
use Illuminate\Foundation\Http\FormRequest;
|
2017-11-06 16:42:37 -08:00
|
|
|
use Illuminate\Http\Request;
|
2017-11-04 17:06:14 -07:00
|
|
|
|
|
|
|
class CustomFieldRequest extends FormRequest
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Determine if the user is authorized to make this request.
|
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function authorize()
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the validation rules that apply to the request.
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
2017-11-06 16:42:37 -08:00
|
|
|
public function rules(Request $request)
|
2017-11-04 17:06:14 -07:00
|
|
|
{
|
2017-11-06 16:42:37 -08:00
|
|
|
$rules = [];
|
|
|
|
|
2023-04-25 21:30:47 -07:00
|
|
|
$rules['associate_fieldsets.*'] = 'nullable|integer|exists:custom_fieldsets,id';
|
|
|
|
|
2021-06-10 13:15:52 -07:00
|
|
|
switch ($this->method()) {
|
2017-11-06 16:42:37 -08:00
|
|
|
|
|
|
|
// Brand new
|
|
|
|
case 'POST':
|
|
|
|
{
|
2021-06-10 13:15:52 -07:00
|
|
|
$rules['name'] = 'required|unique:custom_fields';
|
2017-11-06 16:42:37 -08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2017-11-06 20:05:40 -08:00
|
|
|
// Save all fields
|
|
|
|
case 'PUT':
|
2021-06-10 13:15:52 -07:00
|
|
|
$rules['name'] = 'required';
|
2017-11-06 20:05:40 -08:00
|
|
|
break;
|
|
|
|
|
|
|
|
// Save only what's passed
|
|
|
|
case 'PATCH':
|
|
|
|
{
|
2021-06-10 13:15:52 -07:00
|
|
|
$rules['name'] = 'required';
|
2017-11-06 20:05:40 -08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2017-11-06 16:42:37 -08:00
|
|
|
default:break;
|
|
|
|
}
|
|
|
|
|
|
|
|
$rules['custom_format'] = 'valid_regex';
|
|
|
|
|
|
|
|
return $rules;
|
2017-11-04 17:06:14 -07:00
|
|
|
}
|
2023-04-25 21:30:47 -07:00
|
|
|
|
|
|
|
public function messages()
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
'associate_fieldsets.*.exists' => 'Invalid fieldset',
|
|
|
|
];
|
|
|
|
}
|
2017-11-04 17:06:14 -07:00
|
|
|
}
|