File "ShippingQuoteRequest.php"

Full Path: /home/clickysoft/public_html/jmapi5.clickysoft.net/app/Http/Requests/User/ShippingQuoteRequest.php
File size: 1.54 KB
MIME-type: text/x-php
Charset: utf-8

<?php

namespace App\Http\Requests\User;

use App\Rules\ValidateProductPrice;
use Illuminate\Foundation\Http\FormRequest;

class ShippingQuoteRequest extends FormRequest
{

    public function rules()
    {
        return [
            'career_code' => [
                'required'
            ],
            'service_code' => [
                'nullable'
            ],
            'package_type_code' => [
                'required_with:service_code'
            ],
            'products' => [
                'required',
                'array'
            ],
            'products.*.product_id' => [
                'required',
                'exists:products,id'
            ],
            'products.*.price_id' => [
                'required',
                new ValidateProductPrice,
            ],
            'products.*.quantity' => [
                'required',
                'min:1',
            ],
            'shipping_address_id' => [
                'nullable',
                'exists:address_books,id'
            ],
            'zipcode' => [
                'required_without:shipping_address_id',
                'integer',
                'regex:/^[0-9]{5}$/'
//                'regex:/^\d{5}(-\d{4})?$/'
            ],
            'is_residential' => [
                'required',
                'boolean'
            ],
        ];
    }

    public function messages()
    {
        return [
            'zipcode.integer' => 'Zipcode must only contain numbers.',
            'zipcode.regex' => 'Zipcode length must be 5 digits.',
        ];
    }
}