I want to use Laravel Unique validator with the implementation of softdeletes. I've been try many times but it produce an error like this. What should i do? Thanks in advance. Here's my code example.
public function store(Request $request)
{
$request->validate([
'nama' => 'required',
'nim' => [
'required',
'size:10',
Rule::unique('students')->where(function ($query) {
return $query->where('deleted_at', NULL);
})
],
'email' => 'required|email',
]);
Student::create([
'major_id' => $request->major_id,
'nama' => $request->nama,
'slug' => Str::of($request->nama)->slug('-'),
'nim' => $request->nim,
'email' => $request->email,
]);
return redirect('/students')->with('status', 'Success');
}
