ardent icon indicating copy to clipboard operation
ardent copied to clipboard

InvalidArgumentException on unique rule

Open pedronalbert opened this issue 9 years ago • 1 comments

I'm trying to create a unique rule but this throw "Validation rule unique requires at least 1 parameters." when save()

  public static $rules = [
    'type' => 'required',
    'state' => 'required',
    'number' => 'required|unique'
  ];
    public function store(Request $request) {
        $inputsData = $request->only('type', 'state', 'number');

        $newBus = new Bus($inputsData);

        if($newBus->save()) {
            $newBus->createSeating();

            return response()->json($newBus);
        } else {
            return response()->validation_error($newBus->errors());
        }
    }
    public function update(Request $request, $id) {
        $inputsData = $request->only('type', 'state', 'number');

        $bus = Bus::findOrFail($id);

        if($bus->updateUniques($inputsData)) {

            return response()->json($bus);
        } else {
            return response()->validation_error($bus->errors());
        }
    }

pedronalbert avatar Nov 27 '15 18:11 pedronalbert

+1 as I do get this error also, still trying to find a fix.

duongtdvn avatar Dec 15 '15 17:12 duongtdvn