2017-09-14 19:21:00 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Http\Requests\Setting;
|
|
|
|
|
|
2019-11-16 07:21:14 +00:00
|
|
|
use App\Abstracts\Http\FormRequest;
|
2017-09-14 19:21:00 +00:00
|
|
|
|
2019-11-16 07:21:14 +00:00
|
|
|
class Category extends FormRequest
|
2017-09-14 19:21:00 +00:00
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* Get the validation rules that apply to the request.
|
|
|
|
|
*
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
|
|
|
|
public function rules()
|
|
|
|
|
{
|
2023-03-15 13:37:26 +00:00
|
|
|
$types = collect(config('type.category'))->keys();
|
|
|
|
|
|
2026-03-10 19:15:51 +00:00
|
|
|
$type = $this->request->get('type');
|
|
|
|
|
$config = config('type.category.' . $type, []);
|
|
|
|
|
$code_hidden = !empty($config['hide']) && in_array('code', $config['hide']);
|
|
|
|
|
$code = $code_hidden ? 'nullable|string' : 'required|string';
|
2026-03-09 19:44:15 +00:00
|
|
|
|
2017-09-14 19:21:00 +00:00
|
|
|
return [
|
|
|
|
|
'name' => 'required|string',
|
2026-03-09 19:44:15 +00:00
|
|
|
'code' => $code,
|
2023-03-15 13:37:26 +00:00
|
|
|
'type' => 'required|string|in:' . $types->implode(','),
|
2024-02-09 08:37:16 +00:00
|
|
|
'color' => 'required|string|colour',
|
2017-09-14 19:21:00 +00:00
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
}
|