Support the ongoing development of →
Validation Laravel Requests
Last updated 1 year ago.

See if this works,

$this->validate($request, [
    'subject' => ['required'],
    'name' => ['required', Rule::unique('exam','name')
            $q->where('subject', $this->get('subject'));

Class 'App\Http\Controllers\Rule' not found

$this->validate($requ- list text hereest, [ 'subject' => ['required'], 'name' => ['required', Rule::unique('exam','name') ->ignore($this->route('id')) ->where(function($q){ $q->where('subject', $this->get('subject')); }) ]);

so i put this use Illuminate\Validation\Rule;

but now i'm getting this error

Method [route] does not exist. here is a preview of the table. please have a look

i want the combination of the "name" and "subjectId" to be unique in "exam" table

thanks for you answer


Ok I see.

Hopefully This should work.

$this->validate($request, [
    'subject' => ['required'],
    'name' => [
            ->where(function($q) use ($request){
                $q->where('subjectId', $request->get('subjectId'));

Change the query inside the where closure as you need.


Sign in to participate in this thread!

Full Stack Europe

Your banner here too?


We'd like to thank these amazing companies for supporting us

Your logo here?

The Laravel portal for problem solving, knowledge sharing and community building.

© 2023 - All rights reserved.