check() and $this->ajax(); } /** * Get the validation rules that apply to the request. * * @return array */ public function rules(): array { return [ 'insta_id' => [ 'required_without:username', 'digits_between:17,18', function ($attribute, $value, $fail) { /** @var \Illuminate\Support\Collection<\App\Lib\Instagram\Objects\TopMedia> */ $igMediaList = Cache::get('top_media_ajax_fetch'); if ( !$igMediaList->contains(function ($lValue) use ($value) { /** @var \App\Lib\Instagram\Objects\TopMedia $lValue */ return $lValue->insta_id === \intval($value); }) ) { $fail("$attribute Le media n'existe pas dans la liste en cache"); } } ], 'username' => [ 'required_without:insta_id', 'string', 'min:1', function ($attribute, $value, $fail) { /** @var \Illuminate\Support\Collection<\App\Lib\Instagram\Objects\TopMedia> */ $igMediaList = Cache::get('top_media_ajax_fetch'); if ( !$igMediaList->contains(function ($lValue) use ($value) { /** @var \App\Lib\Instagram\Objects\TopMedia $lValue */ return $lValue->username === $value; }) ) { $fail("$attribute Le media n'existe pas dans la liste en cache"); } } ], ]; } }