Questions tagged [eloquent-relationship]

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

944 questions
-1
votes
3 answers

Laravel Eloquent : one to many relationship with distinct

Need to get distinct row. Is there any way in laravel eloquent to avoid the duplication of data. Need to get unique users after joining with image table. Now, I'm getting the same users, need to avoid the repetition of the same user. Model…
-1
votes
2 answers

Deleting eloquent relationship laravel

I have three tables, Order, OrderItem and GoldSilver. OrderItem has an order_id from Order table and OrderItem has gold_silver_id. So, Upon deleting Order I want to delete related OrderItem and GoldSilver. I can delete OrderItem through Laravel…
-1
votes
2 answers

laravel relaion many to many

hello family I am working on a school management project but I have a problem with relations: I have a table of years, students, level now a pupil can register only once in a level during a school year, during a school year several pupils can…
-1
votes
1 answer

Laravel calculate Total balance by rates

I have an ecommerce site with 4 tables (Users, Vendors, Products and Orders). Vendor here means a shop. A User is a person and can own many different Vendors. These Vendors can have many different products (Vendor hasMany Product relationship and…
-1
votes
1 answer

Is there any way to use raw sql or i'm stuck with laravel-eloquent?

I'm trying to migrate an application developed in 2007 and add and api to it so I can easy develop and sync data with the new App I started a laravel project with the old database just to create the api the old database diagram look like this: Too…
-1
votes
1 answer

how do i go getting this eloquent relationship right?

I have an user model and a student model which I have created relationship for, but when I try to $student->user->fullname I get this error "trying to get property fullname of non-object" here is my user model code:
-1
votes
2 answers

Can Anyone help me to bring a tree structure in laravel like this

Desired Output is like : Parent Cat 1 Parent Cat 2 Child Cat 1 Child Cat 2 Parent Cat 3 Child Cat 3 but i need to do like this while the table structure is like below id | cat_name | cat_parent_id --- | --------------|…
-1
votes
3 answers

Update fields from two tables in Laravel

I have 2 models: customer and customerName. In my customer Controller I try to create a method that update fields from both tables. Any idea? Thanks! CustomerController public function update(Request $request, Customer $customer) { $customer =…
Beusebiu
  • 1,433
  • 4
  • 23
  • 68
-1
votes
1 answer

How can I use Null coalescing ?? operator of php inside of an if statement with Laravel Eloquents to check object exists or not

How can I use Null coalescing ?? operator of PHP inside of an if statement with Laravel Eloquents to check an object exists or not? Currently, it is showing this error: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'posts.categories_id'…
-1
votes
4 answers

GroupBy from relations using laravel eloquent

I have TypeOfVehicle model that has many Vehicle. How can I group all vehicles by type of vehicle name with counts to get something like this [ 'Sedan' => 10, 'SUV' => 25, 'Crossover' => 5 ]
knubbe
  • 1,132
  • 2
  • 12
  • 21
-1
votes
2 answers

The equivalence of the AND statement in a ON statement (JOIN) in EloquentORM

Take a look at the query below: SELECT v*, s.* FROM videos v INNER JOIN subtitles s ON (s.subtitle_id = v.video_id AND s.language = 'en') WHERE v.video_id = 1000 I want to find the equivalent data retrieval action for a Laravel / Eloquent ORM…
Julian
  • 4,396
  • 5
  • 39
  • 51
-1
votes
1 answer

I have to join 6 different tabel in Laravel using Eloquent

I have 6 different tables in my database and I have to fetch value from column type, id, title, created_at, updated_at, imported, import_url, cover_type, profile_image from all 6 tables and some extra values from column start_date and location from…
Anurag
  • 1
  • 1
-1
votes
1 answer

How to get polymorphic relationship type while eager loading in Laravel Eloquent?

While querying polymorphic relationship existence or absence, Laravel Eloquent provides whereHasMorph and whereDoesntHaveMorph methods which really helpful to create queries related to the types. But what about for eager loads? Here is the…
-1
votes
1 answer

How to use multiple "where like" in a relationship - Laravel

I have 4 tables in my DB. User , user_details, tags and taggables. By using the user table I am getting user along with user detail and tags. Following is table schema Table user: id, name, email, password Table user_details user_id, about,…
Haris Khan
  • 15
  • 3
-1
votes
1 answer

Laravel Compare Multiple Many-to-many Relationships

I am using Laravel Eloquent to retrieve data. This is what my database looks like. I have the user's preference in one pivot table and the agency's preference in the other: Can anyone help me come up with an Eloquent command that will return all…
1 2 3
62
63