check(); } /** * Get the validation rules that apply to the request. */ public function rules(): array { return [ 'message' => 'required|string|max:255|min:5', 'to' => [ 'required', Rule::exists('customers', 'username'), // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundBeforeLastUsed function (string $attribute, $value, callable $fail) { /** @var \App\Models\Customer|null */ $authCustomer = Auth::guard('club')->user(); $customer = Customer::query()->where('username', $value)->firstOrFail(); if ( BlockList::query() ->whereHas('customer', fn (Builder $q) => $q->where('id', $customer->getKey())) ->whereHas('blocked', fn (Builder $q) => $q->where('id', $authCustomer->getKey())) ->exists() ) { $fail(trans('Vous ne pouvez pas envoyer de message à cet utilisateur')); } if ( BlockList::query() ->whereHas('customer', fn (Builder $q) => $q->where('id', $authCustomer->getKey())) ->whereHas('blocked', fn (Builder $q) => $q->where('id', $customer->getKey())) ->exists() ) { $fail(trans('Vous avez bloqué cet utilisateur')); } }, ], ]; } }