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

<?php

namespace App\Http\Requests\Admin\Banner;

use Illuminate\Foundation\Http\FormRequest;

use Illuminate\Http\Request;

use Illuminate\Validation\Rule;

class BannerPostRequest 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 [       
                'type' => ['required', Rule::in(BANNER, BANNER_PRODUCT)],
                'title' => ['required_if:type,'.BANNER, 'max:255'],
                'picture' => [Rule::requiredIf(!$request->banner_id && $request->type == BANNER), 'mimes:jpg,png,jpeg', 'exclude_if:type,'.BANNER],
                'link' => $request->type == BANNER ? ['url', 'required'] : [],
                'description' => ['required_if:type,'.BANNER],
                'product_id' => ['required_if:type,'.BANNER_PRODUCT, 'exists:products,id', 'exclude_if:type,'.BANNER]
        ];
    }

    /**
    * Custom Validation Errors.
    *
    * @return array
    */
    public function messages()
    {
        return [
            'required_if' => "The :attribute field is required when the type is banner",
            'product_id.required_if' => tr('product_field_required'),
        ];
    }
}
Back to Directory File Manager