N
N
NubasLol2019-01-08 21:35:32
Laravel
NubasLol, 2019-01-08 21:35:32

Laravel validation not working, what could be the reason?

I made a separate class-request, in it I wrote

'order_id' => [
                'required',
                'integer',
                Rule::exists('orders')->where(function ($query) {
                    $query->where('id', $this->order_id)->where('user_id', auth()->id());
                }),
            ],

As a result
Undefined column: 7 ERROR: column "order_id" does not exist\
Perhaps you meant to reference the column "orders.user_id". (SQL: select count(*) as aggregate from "orders" where "order_id" = 176 and ("id" = 176 and "user_id" = 221))

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexey Ukolov, 2019-01-08
@NubasLol

Rule::exists('orders', 'id')->where(function ($query) {
    $query->where('user_id', auth()->id());
}),

https://laravel.com/docs/5.7/validation#rule-exists

E
Evgeny Perin, 2019-01-08
@seoperin

$query->where('orders.id', $this->order_id)->where('orders.user_id', auth()->id());

try like this

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question