Skip to content

Tag: eloquent

Laravel: UpdateOrCreate on Relation?

A user hasOne car. users cars Inside the User class I have I want to call updateOrCreate on the relation Model like this: However, I get the error message “SQLSTATE[42S22]: Column not found: 1054 Unknown column ‘id’ in ‘where clause’ (SQL: update cars set color = red, energy = 0.…

Laravel: Count number of rows in a relationship

I have the following relationship: A venue has many offers A offer has many orders I have the following Eloquent model to represent this: I want to determine the total number of orders for venues with location_id = 5 using Laravel’s Eloquent model. The only way I managed to do this is as follows: Howeve…

Laravel HasMany across multiple connections

I want to retrieve Offers related to Offer on a second table offer_related because I can’t change the schema of the Offer table. I have two databases on different connections, offers on one, and offer_related on another. For the sake of argument, I’m going to name databases as follows for clarity …