# fluent-cart/1.6.4/app/Modules/Shipping/Http/Requests/ShippingMethodRequest.php

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

- Page: https://pluginprobe.com/plugins/fluent-cart/1.6.4/code/app/Modules/Shipping/Http/Requests/ShippingMethodRequest.php
- Raw: https://pluginprobe.com/plugins/fluent-cart/1.6.4/raw/app/Modules/Shipping/Http/Requests/ShippingMethodRequest.php
- Modified: 2026-04-20T13:45:50+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/Modules/Shipping/Http/Requests/ShippingMethodRequest.php#L10-L20`.

```php
<?php

namespace FluentCart\App\Modules\Shipping\Http\Requests;

use FluentCart\Framework\Foundation\RequestGuard;
use FluentCart\Framework\Support\Arr;

class ShippingMethodRequest extends RequestGuard
{

    public function beforeValidation()
    {
        $data = $this->all();
        $data['is_enabled'] = (string)(Arr::get($data, 'is_enabled', 0)) === '1' ? 1 : 0;
        return $data;
    }

    /**
     * @return array
     */
    public function rules()
    {
        return [
            'zone_id'    => 'required',
            'title'      => 'required|string|maxLength:192',
            'amount'     => 'nullable',
            'type'       => 'required|string|maxLength:192',
            'settings'   => 'nullable|array',
            'states'     => 'nullable|array',
            'is_enabled' => 'nullable|integer|in:0,1',
            'method_id'  => 'nullable|integer',
            'meta'       => 'nullable|array',
        ];
    }

    /**
     * @return array
     */
    public function messages()
    {
        return [
            'zone_id.required' => esc_html__('Shipping zone is required.', 'fluent-cart'),
            'title.required'   => esc_html__('Shipping method title is required.', 'fluent-cart'),
            'type.required'    => esc_html__('Shipping method type is required.', 'fluent-cart')
        ];
    }

    /**
     * @return array
     */
    public function sanitize()
    {
        return [
            'zone_id'                    => 'intval',
            'title'                      => 'sanitize_text_field',
            'type'                       => 'sanitize_text_field',
            'amount'                     => 'sanitize_text_field',
            'is_enabled'                 => 'sanitize_text_field',
            'method_id'                  => 'intval',
            'states'                     => function ($value) {
                if (is_array($value)) {
                    return array_map('sanitize_text_field', $value);
                }
                return $value;
            },
            'settings.configure_rate'    => 'sanitize_text_field',
            'settings.class_aggregation' => 'sanitize_text_field',
            'settings.weight_tiers'      => function ($value) {
                if (!is_array($value)) {
                    return [];
                }
                return array_map(function ($tier) {
                    return [
                        'min'  => floatval($tier['min'] ?? 0),
                        'max'  => floatval($tier['max'] ?? 0),
                        'cost' => floatval($tier['cost'] ?? 0),
                    ];
                }, $value);
            },
            'meta'                       => function ($value) {
                if (!is_array($value)) {
                    return [];
                }

                $sanitized = [];
                foreach ($value as $key => $val) {
                    if (is_string($val)) {
                        $sanitized[$key] = sanitize_text_field($val);
                    }
                }
                return $sanitized;
            }
        ];
    }

}

```
