Viewing File: /home/ubuntu/walnutminds-ecom-backend-base/app/Http/Requests/Admin/Product/ProductPostRequest.php

<?php

namespace App\Http\Requests\Admin\Product;

use Illuminate\Foundation\Http\FormRequest;

use Illuminate\Http\Request;

use Illuminate\Validation\Rule;

use App\Rules\DiscountRule;

class ProductPostRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules(Request $request)
    {
        return [
                'name' => 'required|max:255',
                'category_id' => 'required|exists:categories,id',
                'sub_category_id' => 'required|exists:sub_categories,id',
                'original_price' => 'required|numeric|min:1|max:100000',
                'price' => 'nullable',
                'quantity' => 'required|numeric',
                'gross_weight' => 'required|numeric|min:0|max:10000',
                'unit' => 'required|max:50',
                'description' => 'required',
                'files.*' => $request->product_id ? 'mimes:jpg,png,jpeg|exclude' : 'required|mimes:jpg,png,jpeg|exclude',
                'operation' => ['required', Rule::in(ADD, MINUS), 'exclude'],
                'discount' => ['nullable', 'exclude'],
                'discount_type' =>  ['required_with:discount', Rule::in(DISCOUNT_TYPE_PERCENTAGE, DISCOUNT_TYPE_FLAT_PRICE), new DiscountRule($request->discount, $request->discount_type, $request->original_price), 'exclude'],
                'thc_drug_content' => ['nullable', Rule::in(YES, NO)],
                'thc_from' => ['nullable', 'numeric', 'min:0', 'max:200000', Rule::requiredIf($request->thc_drug_content == YES)],
                'thc_to' => ['nullable', 'numeric', 'min:0', 'max:200000', request('thc_from') ? 'gt:thc_from' : 'gte:thc_from' ],
                'thc_unit' =>  ['nullable', 'required_with:thc_from,thc_to', Rule::in(get_cannabidiol_units())],
                'thc_per_from' => 'nullable|numeric|min:0|max:200000',
                'thc_per_to' => ['nullable', 'numeric', 'min:0', 'max:200000', request('thc_per_from') ? 'gt:thc_per_from' : 'gte:thc_per_from' ],
                'thc_per_unit' =>  ['nullable', 'required_with:thc_per_from,thc_per_to', Rule::in(get_cannabidiol_units())],
                'cbd_drug_content' => ['nullable', Rule::in(YES, NO)],
                'cbd_from' => ['nullable', 'numeric', 'min:0', 'max:200000', Rule::requiredIf($request->cbd_drug_content == YES)],
                'cbd_to' => ['nullable', 'numeric', 'min:0', 'max:200000', request('cbd_from') ? 'gt:cbd_from' : 'gte:cbd_from' ],
                'cbd_unit' =>  ['nullable', 'required_with:cbd_from,cbd_to', Rule::in(get_cannabidiol_units())],
                'cbd_per_from' => 'nullable|numeric|min:0|max:200000',
                'cbd_per_to' => ['nullable', 'numeric', 'min:0', 'max:200000', request('cbd_per_from') ? 'gt:cbd_per_from' : 'gte:cbd_per_from' ],
                'cbd_per_unit' =>  ['nullable', 'required_with:cbd_per_from,cbd_per_to', Rule::in(get_cannabidiol_units())],
                'plant_type' => 'max:255',
        ];
    }

    /**
    * Custom Validation Errors.
    *
    * @return array
    */
    public function messages()
    {
        return [  'mimes' => 'The file must be a type of: :values.' ];
    }
}
Back to Directory File Manager