Questions tagged [wherehas]
32 questions
0
votes
1 answer
Nested relation whereHas in laravel
I wanna ask about some nested relation using whereHas query in laravel, well for the first I will explain the model first before I going through into my main case.
this is my model :
StockIn.php
class StockIn extends Model {
protected…

ProLuck
- 331
- 4
- 18
0
votes
1 answer
Laravel Eloquent only get parent if latest child created_at < than 5 years from now
I have a customer model with many transactions, and I need to get customers only where the customer's latest transaction is < 5 years from now. So the result was a customer who had any transaction that matched the condition. Even the transaction…

wahyudwikrisnanto
- 11
- 1
0
votes
2 answers
How to get data HasMany() using WhereHas in Laravel
I want to get data from my table " Package " by using its model " Package "
and in this model " Package " it have a HasMany() named histories() relation to model " History "
so i want to only get data that have histories
here is my controller
public…

M Andre Juliansyah
- 117
- 1
- 2
- 14
0
votes
0 answers
WhereHas with a condition
I have this relationship in tables.
consumers;id, name, site_id, tier_id
tiers:id, name, site_id
categories: id, name, site_id
consumer_categories: consumer_id, category_id
consumer_tiers: category_id, tier_id
And this is how I have set it up in…

Ali Rasheed
- 2,765
- 2
- 18
- 31
0
votes
1 answer
Laravel query builder - how to select a model whereHas one of multiple relationships
I have a Shop model that can has three relationships: Specials, Discounts and ThrowOuts. I want to select all Shops that have data in any one of those three relationships, but mask the ones that don't have any at all.
I also want to limit the search…

Abraham Brookes
- 1,720
- 1
- 17
- 32
0
votes
2 answers
Search in last record of relationship - Laravel (Eloquent)
i need to search in last record of an relationship in Laravel 7. Here is my code, hope u understand my question :)
$Collection = ServiceRequest::whereHas('ServiceRequestSignatureFlows', function ($query) use ($ou_id) {
…
0
votes
2 answers
how to get the data using whereHas clauses and relationship?
user table
id
email
password
membership table
id
user_id
expiry_date
delivery_day_innum(eg:like 7,8 days)
deliverdetailes table
id
user_id
created_at
updated_at
goods table
id
user_id
name
qty
goods…

Razeev Kumar Yadav
- 13
- 6
0
votes
2 answers
How can i put condition in relation in laravel?
I have File model that it store my images, and i have shop model, the shop can have many images and in shop model i wrote this code:
public function Files()
{
return $this->hasMany('system\models\file', 'attachment_id');
}
and i…

Farzin Bidokhti
- 71
- 1
- 10
0
votes
1 answer
where Has Condition on a hasMany relationship in Laravel 5.8
I have a relationship in a model FeeModuleModel as shown below
public function heads()
{
return $this->hasMany('App\Models\FeeHeadModel','location_id','id');
}
and in my controller file i need to fetch only the values FeeModuleModel…

Asish Antony
- 85
- 2
- 11
0
votes
1 answer
Laravel6 WhereHas Error 500 when using AJAX
im new to Laravel and facing an interesting Issue right now in my App.
I have 3 tables.
Producers
id
producer_name
Types
id
type_name
Models
id
model_name
device_type_id
device_producer_id
Within my Producers Model I have defined the…

Mike Auer
- 5
- 2
0
votes
3 answers
query: {} return at whereHas in postman but data there is in table. Laravel
in CitizenService there is service_id but this query returning query: {} in postman. in model connected service();
$query = CitizenService::whereHas('service', function (Builder $query) {
$query->where('service.id', 1);
});
return…

Farrux Choriyev
- 179
- 1
- 5
0
votes
2 answers
Laravel 5.7 - Advanced where() query inside a when() function
I am having problems with a query that uses values from multiple form inputs, and each one is optional.
The idea is to find the applications of an ISP (ie. technical services, installations, etc) assigned to a technician.
Due to the inputs being…

pmpato
- 11
- 3
0
votes
2 answers
Laravel whereHas not getting any results?
I have a Restaurant Model, each restaurant has a Contact Model,
and each Contact is related to a City Model:
Restaurant.php:
public function contact()
{
return $this->hasOne('App\Contact','rest_id');
}
Contact.php:
public function restaurant()
{
…

aghed aljlad
- 1,765
- 2
- 14
- 18
0
votes
1 answer
How can I implement Laravel Eloquent wherehas count question?
I have bookings and addon table.
bookings has many addons.
I want to get bookings with addon type Optional Tour
I tried this
$bookings = Booking::with([
"add_ons",
])
->whereHas("add_ons",function($q){
…

Jaeyoung Heo
- 87
- 1
- 11
-1
votes
1 answer
what can i do if i have components have relation with same model so,i want to unreturn this components if its haven't this model?
i have at least 8 components have same relation with course model i want to un return this component if this course is hidden
i tried to make it in global scope but still need to do in all these component's model whereHas and with how can i do these…