Questions tagged [eloquent-relationship]

Official documentation: https://laravel.com/docs/7.x/eloquent-relationships

944 questions
0
votes
3 answers

How to split orders between sellers and buyers Laravel?

I'm building a platform where a user can sign up and add products to sell. Also another user can buy products listed. When a buyer place an order, i want it to be seen by a seller(user) who listed the product. Right now all users can see all orders…
joh
  • 238
  • 1
  • 5
  • 25
0
votes
1 answer

Retrieve values from related table foreign key using Eloquent

Sorry if the question isn't clear.. I'm not super fluent in databases. I have three tables: companies equipment parts ----------- ----------- ----------- id id id name company_id …
Sandy
  • 2,572
  • 7
  • 40
  • 61
0
votes
3 answers

Speed up query through laravel relationships

There are 3 models: First (first_id) Connection (connection_id, first_id, product_id) Second (second_id, product_id) I would like to connect the three models together using laravel relationships First->joined to Connection though…
user2101517
  • 700
  • 3
  • 11
  • 22
0
votes
0 answers

Data missing on belongs to many relation

I'm trying to get data from a Many to Many Relationship using Eloquent in Laravel. Every time I do this I get a Data Missing error. I've tried the following to get the data: return $workers = Worker::first()->workers_sub_categories; return…
0
votes
2 answers

How to render data from a different table in hasMany relationship Laravel?

On a jobs site I'm making I have a table for users, candidate_skills and skills. A user has many candidate_skills. Each candidate_skill belongs to a user and also belongs to a skill. The candidate_skills table has these columns: id user_id…
Connor Leech
  • 18,052
  • 30
  • 105
  • 150
0
votes
0 answers

can i have the user click a button to then add something to a database

I have the system where I can manually change the database and the bike id will link to the favourite id and will show on the favourite page. What I need now is to allow the user to click a favourite button on the bike img and it will save the bike…
0
votes
0 answers

relational Database delete in laravel

I am setting up a two database table, sale item and sale. When an admin make an inventory multiple sale item can added. After complete my sale inventory, i want to delete sale but i do not want to delete sale item table. My Sale Item migration table…
0
votes
1 answer

Eloquent Relationship with a conditional scope

I'm working on a Fantasy sports app. The models I am working with are FantasyPlayer, PlayerGame, TeamGame FantasyPlayer can have many PlayerGame and can have many TeamGame public function PlayerGame() { return…
thindery
  • 1,164
  • 4
  • 23
  • 40
0
votes
1 answer

How to get AVG value by pivot fields

I have some problem, I don't understand how to count AVG value when get all value from model. I have 2 model's. First it's AdminProduct - hold base info about product. Second model it's - PartnerOffer - hold partners offers for AdminProduct. And i…
0
votes
2 answers

How to Union/Merge three database tables with exact schema but different data while taking care of eloquent relationships?

In my Laravel application, I have three database tables with exact same structure/schema and then there is a 'users' table containing all users. All three tables have the following structure... table1 id    user_id    description   …
Kashif
  • 495
  • 1
  • 5
  • 16
0
votes
2 answers

Laravel Eager-loading works only when calling attribute

I've defined my Slot model to load the relations from User model like so : public function userAssignedFull(): HasOne { return $this->hasOne(User::class,'id','user_assigned'); } ('slots' table contains 'user_assigned' field by which I connect…
Yaron
  • 1,655
  • 6
  • 20
  • 38
0
votes
1 answer

retrieve data from table based on a foreignKey Laravel

So I have 2 tables, articles and sub_categories. They are linked throug Eloquent: articles has many sub_categories's, and sub_categories belongsTo article. They are linked with foreign keys as such: in "article" categorie_id. How do I retrieve the…
saif
  • 13
  • 1
  • 4
0
votes
2 answers

Working with whereDoesntHave() in Laravel 5.4

How do I implement a scope where in the user will claim a reward on a specific level and once they claim their rewards, the reward field will no longer display the reward that they have claimed. So for example: The user is on level 20, on his reward…
John Carlo
  • 54
  • 2
  • 13
0
votes
1 answer

How to insert into a table based on an Eloquent relationship an array of foreign keys

I have two models TeamMember and ProjectRequest. A TeamMember can have one ProjectRequest, that is why I created the following Eloquent relationship on TeamMember: class TeamMember extends Model { // protected $table = 'team_members'; protected…
0
votes
1 answer

Order By before Group By an Eloquent belongsToMany relationship

I want to get unique posts ordering by project_id, basically, if there are duplicated posts I want the one in which project_id is not null. Is there any way to get this? This code is returning unique posts, but they are not ordered by…