<?php

namespace App\Http\Requests\Blog;

use Illuminate\Contracts\Validation\Validator;
use Illuminate\Foundation\Http\FormRequest;

class CommentRequest extends FormRequest
{
    public $validator = null;

    /**
     * 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()
    {
        return [
            "name" => "required|string|min:2",
            "email" => "required|email|max:255",
            "comment" => "required|min:2",
            "post_id" => "required|exists:posts,id"
        ];
    }

    public function failedValidation(Validator $validator)
    {
        if($validator->fails()) {
            return [
                "type" => "alert-danger",
                "message" => "Please check the input fields"
            ];
        }
    }
}
