The issue of not using whereNotExists clause correctly in Laravel 8 Eloquent remains unresolved
P粉287726308
P粉287726308 2023-09-05 16:08:35
0
1
337
<p>I have two tables, one is a table with different users and the other is an invoice table called "factures" which has a foreign key userid which I call client_id. What I want to get is the number of customers that were created by a certain admin and don't have an invoice yet. This is the code I tried: </p> <pre class="brush:php;toolbar:false;">$clients = User::select('id') ->where([['created_by',$membre_id],['role','Client']]) ->orWhere([['updated_by',$membre_id],['role','Client']]) ->whereNotExists(function($query) { $query->select(DB::raw('client_id')) ->from('factures') ->where('created_by',$member_id); })->get();</pre> <p>But this query returns me all customers created by $member_id, no exceptions. Is there anything wrong with my query? </p>
P粉287726308
P粉287726308

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!