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

See if this works,

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

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.

http://aice.webtutorialguru.com/faltu/db.jpg 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

0

Ok I see.

Hopefully This should work.

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

Change the query inside the where closure as you need.

0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

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

Your logo here?

Laravel.io

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

© 2024 Laravel.io - All rights reserved.