Support the ongoing development of Laravel.io →
Requests Eloquent Validation
Last updated 2 years ago.
0

check your controller, do not forget this

use Template

0

@danielzepp not sure what you mean, I have use App\Template in both the Request and Controller classes

in my Controller I have

public function update(Template $template, TemplateRequest $request)

in my RouteServiceProvider I have

Route::model('Template', App\Template::class);
Last updated 7 years ago.
0

OK found the trick. Here is the solution. I use segment to identify the slug to ignore then also ensure I scope the query to multitenancy.

        $id = $this->segment(4);
        $rules = 
         [
            'name'=>'required',
            'template'=>'required',
            'location'=>[
                'required',
                Rule::unique('templates')->where(function ($query) {
                    $uid = Auth::user()->id;
                    $query->where('user_id',$uid);
                })->ignore($id,'slug')
            ],
             'min_count'=>'required|numeric',
             'template'=>'required',
        ];
          
        return $rules;
0

Sign in to participate in this thread!

Eventy

Your banner here too?

illmatic illmatic Joined 28 Sep 2015

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.