Official documentation: https://laravel.com/docs/7.x/eloquent-relationships
Questions tagged [eloquent-relationship]
944 questions
1
vote
1 answer
Laravel belongs to many by two intermediate tables?
Hi guys I have to create many to many relationship but through a another table. but laravel BelongsToMany give only 1 intermediate table relation
here table structure:
features Table:
+----+-----------+
| id | text |
+----+-----------+
| 1 |…

Viduranga
- 490
- 7
- 17
1
vote
2 answers
Laravel: where statement on with relationship
I want to do a query in laravel with multiple relationships and multiple where statements over the relationships but it doesn't go well.
Here's my code.
$orders = Order::with("customer")
->with("user")
…

Henk-Jan Leusink
- 73
- 5
1
vote
1 answer
Symfony\Component\Debug\Exception\FatalThrowableError Call to a member function get() on bool in laravel?
I want to make a search function of user name and shift pattern id. Search by user shift pattern id works well but not for search by name. For more information, the name is inside the user table while shift pattern id is inside the user shift…

Daisy
- 527
- 1
- 5
- 14
1
vote
2 answers
How to disaplay relation data on update action backpack?
Making CRUD on Backpack for Laravel, and got issue.
I have Domain and domainPrices table
Domain model:
public function domainPrice()
{
return $this->hasOne(DomainPrices::class, 'domain_id', 'id');
}
DomainPrices model:
public function…

mrTall
- 51
- 1
- 6
1
vote
1 answer
getting records by id and querying there relation with 'wherebetween' using Laravel and eloquent
i'm trying to get all measurements from a certain recorder between a certain timespan.
If i remove the "->wherebetween()" part of the query and view the results then I get all the sensors of that recorder and all related measurements of that…

vennot_be
- 17
- 4
1
vote
2 answers
Not able to get the correct relationship count in Laravel
We are trying to build an application in Laravel 8 where we need to fetch some data through complex queries. Let me explain my model structure to you:
I have a Brand model, which is related to multiple Group and SubGroup model with many-to-many…

Ruchira
- 75
- 4
1
vote
1 answer
Determine selected options based on many-to-many relationship
I have three tables: products, categories and category_product.
In my edit form page I'm displaying the categories and subcategories values in a select box.
The chosen category options are saved in the pivot table category_product. This table has…

user2519032
- 819
- 1
- 18
- 34
1
vote
1 answer
Product Search using geolocation of shops
I am new to Laravel and I am trying to search for product using nearby shops
Here is my code
Shop::selectRaw(" id ,
( 6371 * acos( cos( radians(?) ) *
cos( radians( lat ) )
* cos(…

Wasim Rasheed
- 25
- 6
1
vote
1 answer
Laravel filter relationship data
Code
public function getCauserDetails(){
return $this->belongsTo(Users::class, 'causer_id', 'id');
}
$name = testtt; //data to find
ActivityLog::where('causer_id', $userid)
->orWhere('subject_id', $userid)
->with('getCauserDetails')
…

ventures 999
- 149
- 1
- 3
- 12
1
vote
1 answer
can't fetch data from eloquent relationships
I try to fetch specific users who sent to the auth a message using the eloquent relationships
this is the message modal

Monty
- 15
- 4
1
vote
1 answer
Laravel Eloquent Model can't sync with pivot data in Many-to-Many relationship
I would like to sync the data instead of attach the data to the particular relationship.
Pivot relation UserModel code
public function carts(){
return $this->belongsToMany(Product::class,'user_carts')->withPivot('quantity');
}
The…

Miracle Hades
- 146
- 2
- 10
1
vote
1 answer
Show only Followed users post using laravel eloquent relationship
I have 3 model User, Follow, and Post
and these relations are like:
User model:
public function userPosts()
{
return $this->hasMany('App\Model\User\Post');
}
public function follows()
{
return…

Maruf Ahamed
- 11
- 1
- 3
1
vote
1 answer
Laravel 8.x - Storing data with Eloquent Relationship
I've got a User model that hasOne Membership model, with a users table and a memberships table (each entry in the memberships table has a foreign key linked to a user_id).
I've made a registration page that lets the user have a 7 days trial period…

Emmanuele D'Ettorre
- 119
- 2
- 13
1
vote
0 answers
Laravel - big collection and page load slow
I have a project for food ordering. On my object(restaurant) show page I'm calling all product categories with relationship for foreach products that belongs to that category.
I'm also using laravel livewire and this is my…

Milos
- 552
- 2
- 7
- 32
1
vote
3 answers
How to get the "catagory name" in Laravel?
How to get "category name" show in the product table not as "category_id"?
I already try to combine any solutions for this. But still can't solve this prob.
I'd love to hear other suggestions from the masters here.
Category Model

Wina Chan
- 79
- 2
- 9