Official documentation: https://laravel.com/docs/7.x/eloquent-relationships
Questions tagged [eloquent-relationship]
944 questions
1
vote
1 answer
How to display related products through pivot table?
I want to display related item which is in same category.
Here is my 3 table structure
food item table
:
"food_item_id",
"name" ,
"image" ,
food item category table :
"food_item_category_id"
"name"
pivot…

Prince
- 39
- 8
1
vote
4 answers
Attempt to read property "email" on int - Laravel 8
I have a Work model where one of its attributes is the requestor, I am trying to obtain the requestor´s data (I can already obtain the primary key).
In this way I call the view:
$obras = Obra::all();
return view("obra.index",…

Jorge Montejo
- 485
- 1
- 6
- 17
1
vote
2 answers
Update parent model with the HasOne child relationship
I have a League model and a Season model their respective migrations and relationships.
League migration and relations
Schema::create('leagues', function (Blueprint $table) {
$table->unsignedBigInteger("id")->primary();
…

Randolf
- 367
- 1
- 14
1
vote
1 answer
MySQL type CHAR problem in Laravel Eloquent
They say, if you want to find the answer, ask the right question. Really, here I don't know what to ask. Because I don't know what's happening.
Migration:create_table1_table
$table->char('code', 1)->primary();
$table->string('name', 50);
I seeded…

Aaron
- 138
- 1
- 7
1
vote
1 answer
Laravel - HasMany relation not loading
I'm having an issue with a hasMany-relation in my Laravel application.
I'm sure, it is a simple question, but currently I'm struggling with it and can't find the reason.
I have a Model called LandingPage:

dns_nx
- 3,651
- 4
- 37
- 66
1
vote
2 answers
How to deploy relationship in pivot of three model in laravel?
I'm developing a role and permissions based on laravel framework.
I have 3 models :
Weblog
User
Permissions
This is pivot table
user_id , weblog_id , permission_id
Now, a user can have a weblog with permission id 1,2 and another weblog with…

M Mehdizadeh
- 27
- 6
1
vote
1 answer
Is it possible to define a polymorphic relationship through different paths (intermediate model) in Laravel models?
I have the models "Payment", "Estimate" and "Quote", a payment has a polymorphic relationship where it can belong either to a quote or to an estimate, simultaneously a quote can have many estimates, so an estimate is always going to belong to a…

Eliezer Gallego
- 45
- 1
- 4
1
vote
1 answer
Get all child models from parent Many to Many relationship Laravel Eloquent
I am building an ecommerce website using Laravel 5.8 and have the following problem. I want to retrieve all products from a category and its child categories, but to be able to perform filtering queries afterwards in my code. For example price…

Radi
- 159
- 1
- 3
- 13
1
vote
2 answers
How to order column by relationship in Laravel Livewire
I've just followed this tutorial about implementing a data table with Livewire in Laravel.
So far so good. Now I want to order a column that comes from a one-to-one relationship, but I just can't get the sorting work well when selecting this phones…

Pathros
- 10,042
- 20
- 90
- 156
1
vote
1 answer
Laravel Join Tables with intermediate relations
I have 3 Tables.1) Recent Views 2) posts and 3) users. i need to join these three tables with intermediate relation.
recent table
------------
id
post_id
user_id
date
posts table
-----------
id
user_id
post_title
description
date
users…

compulsive coder
- 164
- 1
- 10
1
vote
4 answers
Laravel Eloquent get all Posts stored in categories with Roles
I have four tables in a database named: Category, User, Role and then Post. In the Category table I have a column category_id which by this column i can have multiple child in category.
Every user belongsToMany roles and categories and each category…

DolDurma
- 15,753
- 51
- 198
- 377
1
vote
0 answers
Get related objects via same table join (same pivot table). (Simplify current 3 queries with 1-2 queries using joins)
MRE
CREATE TABLE `publications` (
`id` mediumint unsigned NOT NULL AUTO_INCREMENT,
`title` varchar(200) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL,
PRIMARY KEY (`id`)
) DEFAULT CHARSET=utf8;
INSERT INTO `publications` (`title`)…

Aquaguy
- 357
- 2
- 11
1
vote
1 answer
Codeigniter where not exists does not work
I'm working on Codeigniter project and came across a problem. I would like that my function on my model to bring me the data from the POST table, where POST_ID in CATEGORY Table is not null, without joining the table, so (do not bring back the data…

CodingStudent
- 53
- 1
- 1
- 9
1
vote
1 answer
How to get ID from a relationship table, Laravel
I have 4 table : Users, CompanyRegister, VoucherDetails, Addvoucher.
So the Authenticate Users Id will be submit as user_id in companyRegister table,and then companyRegister ID will be submit as company_id in Voucherdetails table, and lastly…

Ragnar Lothbrok
- 65
- 1
- 1
- 13
1
vote
1 answer
How to make a multiple join query with Eloquent ORM
Long story "short", How can I execute the next MySql query using the Eloquent ORM approach?
Ps: I would like to use the multiple join option instead of multiple selects or subqueries that I know Eloquent ORM performs behind the curtains, I don't…

Martín Cortés
- 11
- 3