app/Http/Requests/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()
    {
        $category= Category::find($this->category);
        switch($this->method())
        {
            case 'GET':
            case 'DELETE':
            {
                return [];
            }
            case 'POST':
            {
                return [
                    'name'=>'min:2|required|unique:categories',
                    'category_id'=>'required'
                ];
            }
            case 'PUT':
            case 'PATCH':
            {
                return [
                   'name'=> 'min:2|required|unique:categories,name,'.$category->id,
                   'category_id'=>'required',
                   'statu_id'=>'required'
                ];
            }
            default:break;
        }
    }
public function rules ( ) { $ category = Category :: find ( $ this -> category ) ; switch ( $ this -> method ( ) ) { case 'GET' : case 'DELETE' : { return [ ] ; } case 'POST' : { return [ 'name' => 'min:2|required|unique:categories' , 'category_id' => 'required' ] ; } case 'PUT' : case 'PATCH' : { return [ 'name' => 'min:2|required|unique:categories,name,' . $ category -> id , 'category_id' => 'required' , 'statu_id' => 'required' ] ; } default : break ; } }
Get the validation rules that apply to the request.
Get the validation rules that apply to the request .