Edit Table Action only populating fields of the first row

Below code works fine when I click on Edit action, fields of that row getting populated
->query(Plan::where('is_private', 0)
->orderBy('price', 'ASC')
)
->query(Plan::where('is_private', 0)
->orderBy('price', 'ASC')
)
But when I update the query and click on Edit for any row, fields of the first row are getting populated
->query(Plan::where('is_private', 0)
->orWhereIn('id', function($query){
$query->select('plan_id')
->from(with(new UserPlan)->getTable())
->where('user_id', auth()->user()->id);
})
->orderBy('price', 'ASC')
)
->query(Plan::where('is_private', 0)
->orWhereIn('id', function($query){
$query->select('plan_id')
->from(with(new UserPlan)->getTable())
->where('user_id', auth()->user()->id);
})
->orderBy('price', 'ASC')
)
My use case: I want to show public plans to all users and show private plan if its assigned to that user.
1 Reply
Mrngstar
MrngstarOP4mo ago
Everything works properly when I use whereIn instead of orWhereIn. select * from plans where id in (select plan_id from user_plans where user_id = 20) and is_private = 0 and plans.deleted_at is null order by price asc for above query, values of that specific rows are getting populating. select * from plans where (id in (select plan_id from user_plans where user_id = 20) or is_private = 0) and plans.deleted_at is null order by price asc For this query, when I click on any row's Edit action,value of only first row are getting populated. Issue resolved with following query
->query(Plan::where(function($query) {
return $query
->whereIn('id', function($query){
$query->select('plan_id')
->from(with(new UserPlan)->getTable())
->where('user_id', auth()->user()->id);
})
->orWhere('is_private', 0);
})
->orderBy('price', 'ASC')
)
->query(Plan::where(function($query) {
return $query
->whereIn('id', function($query){
$query->select('plan_id')
->from(with(new UserPlan)->getTable())
->where('user_id', auth()->user()->id);
})
->orWhere('is_private', 0);
})
->orderBy('price', 'ASC')
)
Want results from more Discord servers?
Add your server