app/Http/Requests/Api/CategoryRequest.php
/**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
Get the validation rules that apply to the request.
@return array
Get the validation rules that apply to the request . @return array
public function rules()
    {
        if($this->isMethod('put'))
        {
            $id = request()->route('id') ;
            $rules =  [
                "name" =>[
                    "required",
                    "string",
                    Rule::unique("categories","name")->ignore($id)
                ]
            ];
        }
        else
        {
            $rules =  [
                "name" => "required|string|unique:categories,name"
            ];
        }
        return $rules ;
    }
public function rules ( ) { if ( $ this -> isMethod ( 'put' ) ) { $ id = request ( ) -> route ( 'id' ) ; $ rules = [ " name " => [ " required " , " string " , Rule :: unique ( " categories " , " name " ) -> ignore ( $ id ) ] ] ; } else { $ rules = [ " name " => " required|string|unique:categories,name " ] ; } return $ rules ; }
Get the validation rules that apply to the request.
Get the validation rules that apply to the request .