0

I have a problem with laravel 8 validation please help

  1. public function store(TodoRequest $request){
    
    $data=request()->all();
    $todo= new Todo();
    $todo->name=$data['name'];
    $todo->Description=$data['Description'];
    $todo->completed=false;
    $todo->save();
    $validated = $request->validated();
    return redirect('/todos');
    

    }

  2. namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class TodoRequest extends FormRequest { /** * 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|unique|min:6|max:255',
        'Description' => 'required',
    ];
}

}

  • https://stackoverflow.com/questions/48533921/validation-rule-unique-requires-at-least-1-parameters – Gert B. Feb 11 '21 at 13:20
  • 3
    Does this answer your question? [Validation rule unique requires at least 1 parameters](https://stackoverflow.com/questions/48533921/validation-rule-unique-requires-at-least-1-parameters) – Gert B. Feb 11 '21 at 13:21

1 Answers1

1

you have to make one small change:

public function rules()
{
    return [
        'name' => 'required|unique:table_name, column_name|min:6|max:255',
        'Description' => 'required',
    ];
}

here table_name should be the name of your table and column_name is 'name' in your case.

Jayesh Tharwani
  • 126
  • 1
  • 2