File "StoreReviewRequest.php"

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

<?php

namespace App\Http\Requests\Admin;

use App\Models\Review;
use Gate;
use Illuminate\Foundation\Http\FormRequest;

class StoreReviewRequest extends FormRequest
{
    public function authorize()
    {
        return true;
    }

    public function rules()
    {
        return [
            'product_id' => [
                'required',
                'integer',
                'exists:products,id',
                'unique:reviews,product_id,NULL,id,user_id,' . auth()->id(),
//                'exists:orders,id,user_id,' . auth()->id(),
            ],
            'rating' => [
                'required',
                'integer',
                'between:0,5',
            ],
            'comment' => [
                'nullable',
                'string',
                'max:500',
            ],
        ];
    }

    public function messages()
    {
        return [
//            'order_id.unique' => 'You have already submitted review against this order.',
            'product_id.unique' => 'You have already submitted review against this product.',
        ];
    }
}