mirror of
https://github.com/Bigherollc/wticreatorstudio.git
synced 2026-07-14 09:01:42 -04:00
75 lines
2.8 KiB
PHP
75 lines
2.8 KiB
PHP
<?php
|
|
|
|
namespace Modules\StudioPlus\Http\Requests;
|
|
|
|
use Illuminate\Validation\Rule;
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
use Modules\StudioPlus\Entities\StudioPlusVideo;
|
|
|
|
class StudioPlusVideoRequest extends FormRequest
|
|
{
|
|
/**
|
|
* Get the validation rules that apply to the request.
|
|
*
|
|
* @return array
|
|
*/
|
|
public function rules()
|
|
{
|
|
$rules = [
|
|
'title' => ['required'],
|
|
'description' => ['nullable'],
|
|
'studio_plus_category_id' => [Rule::requiredIf(!$this->is_short)],
|
|
'visibility' => [Rule::requiredIf($this->filled('is_schedule') && !$this->is_schedule), Rule::in(StudioPlusVideo::visibilityTypes())],
|
|
'schedule_to_publish' => [Rule::requiredIf($this->filled('is_schedule') && $this->is_schedule)],
|
|
'types' => ['nullable', 'array'],
|
|
'asin' => ['required'],
|
|
'product_name' => [Rule::requiredIf(!$this->is_short)],
|
|
'amazon_url' => ['nullable'],
|
|
'studio_plus_asin_id' => [Rule::requiredIf(!$this->is_short), $this->is_short ? '' : 'exists:studio_plus_asins,id'],
|
|
'global_setting_id' => ['nullable', 'exists:global_settings,id'],
|
|
'is_short' => ['nullable', 'boolean'],
|
|
'in_ott' => ['nullable', 'boolean'],
|
|
'brand' => ['nullable', 'string', 'max:100'],
|
|
'metadata.star_ratings' => permissionCheck('studioplus.manage.ott-details') ? ['nullable'] : ['required'],
|
|
'metadata.reasonable_price_point' => permissionCheck('studioplus.manage.ott-details') ? ['nullable'] : ['required']
|
|
];
|
|
|
|
if ($this->video_type['need_asin'] == false) {
|
|
$rules['asin'] = ['nullable'];
|
|
$rules['product_name'] = ['nullable'];
|
|
$rules['brand'] = ['nullable'];
|
|
}
|
|
|
|
|
|
if ($this->studio_plus_video_type_id) {
|
|
$rules['studio_plus_video_type_id'] = ['required', 'exists:studio_plus_video_types,id'];
|
|
$rules['job_request_id'] = $this->video_type['need_job_request'] ? ['required', 'exists:job_requests,id'] : ['nullable'];
|
|
} else {
|
|
if (collect($this->types)->some(fn ($type) => $type === StudioPlusVideo::TYPE_JOB)) {
|
|
$rules['job_request_id'] = ['required', 'exists:job_requests,id'];
|
|
}
|
|
}
|
|
|
|
return $rules;
|
|
}
|
|
|
|
public function messages()
|
|
{
|
|
return [
|
|
'studio_plus_video_type_id.required' => 'The job request field is required.',
|
|
'studio_plus_asin_id.required' => 'The ASIN field is required.',
|
|
'job_request_id.required' => 'The job field is required.',
|
|
];
|
|
}
|
|
|
|
/**
|
|
* Determine if the user is authorized to make this request.
|
|
*
|
|
* @return bool
|
|
*/
|
|
public function authorize()
|
|
{
|
|
return true;
|
|
}
|
|
}
|