# fluent-cart/1.6.4/app/Http/Requests/AttachUserRequest.php

FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler, version 1.6.4. 61 lines.

- Page: https://pluginprobe.com/plugins/fluent-cart/1.6.4/code/app/Http/Requests/AttachUserRequest.php
- Raw: https://pluginprobe.com/plugins/fluent-cart/1.6.4/raw/app/Http/Requests/AttachUserRequest.php
- Modified: 2025-11-20T13:11:16+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/fluent-cart/1.6.4/code/app/Http/Requests/AttachUserRequest.php#L10-L20`.

```php
<?php

namespace FluentCart\App\Http\Requests;

use FluentCart\App\App;
use FluentCart\App\Models\Customer;
use FluentCart\App\Models\User;
use FluentCart\Framework\Foundation\RequestGuard;

class AttachUserRequest extends RequestGuard
{

    /**
     * @return array
     */
    public function rules(): array
    {
        $userId = absint(App::request()->get('user_id'));
        $user = User::query()->with('customer')->find($userId);


        return [
            'user_id' => [
                'required', 'string', 'maxLength:50',
                function ($attribute, $value) use ($user) {

                    if (empty($user)) {
                        return __('User not found.', 'fluent-cart');
                    }

                    if (!empty($user->customer)) {
                        return (__('User already linked to a customer.', 'fluent-cart'));
                    }
                    return null;
                }
            ],
        ];
    }

    /**
     * @return array
     */
    public function messages(): array
    {
        return [
            'user_id.required' => esc_html__('User is required.', 'fluent-cart'),
            'user_id.exists'   => esc_html__('User not found.', 'fluent-cart'),
        ];
    }

    /**
     * @return array
     */
    public function sanitize(): array
    {
        return [
            'user_id' => 'absint',
        ];
    }
}

```
