<?php

namespace App\Http\Requests;

use App\Http\Requests\Request;

class BlockRequest extends Request
{
    /**
     * 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()
    {
            $rules = [
                'name' => 'required',
                'slug' => 'required|unique:blocks',
            ];

            if ($this->isMethod('patch') || $this->isMethod('put')) {
                $rules['slug'] = 'unique:blocks,slug,'.$this->route('block');
            }

            return $rules;
    }

    public function messages()
    {
        return [
            'name.required'     => '名称不能为空',
            'slug.required'     => '别名不能为空',
            'slug.unique'       => '别名已经存在',
        ];
    }
}
