<?php

namespace App\Http\Requests;

use App\Http\Requests\Request;

class LangRequest 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 = [
                'title'     => 'required',
                'name'      => 'required',
                'slug'      => 'required',
                'slug'      => 'unique:langs',
            ];

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

            return $rules;
    }

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