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.…
Tag: eloquent
Getting rank of row in OrderBy desc Eloquent query, How can i make this query work in laravel 5.5 eloquents?)
I am trying to give my users a ranking number for my Laravel hiscores pagination table. This is the MySQL query I found working. I am trying to put make this work as a Laravel eloquent query. My Laravel eloquent query right now: Answer This is my solution. I first added this function to my User Modal Class. N…
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 Eloquent Select Between current month and previous 3 months
i’m trying to build a query that will select all of the records in my DB between now (current month) and the previous 3 months. My query somewhat works, but i want to ignore the day of the month. At the moment, it’s selecting the last # of months to the current DAY as well but i want to ignore
Laravel. morphToMany in cascade mode
I am looking a way of doing the following: Let’s say we have a Theater application and we have three Models: Event, Session and Seat on one hand and Rate on the other hand. We have a morphToMany …
How to select columns from joined tables: laravel eloquent
I have a different problem from this. The scenario is same but I am in need of more filtration of the results. Let me explain. Consider I have 2 tables vehicles id name staff_id distance …
If you don’t want Eloquent to automatically manage created_at and updated_at columns, which of the following will be correct?
Set the model $timestamps property to false. Eloquent will always automatically manage created_at and updated_at columns. Set the model $created_at and updated_at properties to false. I searched the net and found a lot of solution and what must be the real answer to this question, I found that we can disable …
Laravel returns Indirect modification of overloaded element of AppMatch has no effect when pushing new key
I’m having an issue when adding/pushing new key value to the result data, it return Indirect modification of overloaded element of AppMatch. $results[$key][‘competitors’][1]->teamScore = $results[$key][‘competitors’][0]->scoreString; Model Match method Answer Replace array …
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 …
Laravel 5.4 hasManyTrough ‘Call to undefined method IlluminateDatabaseQueryBuilder::hasManyTrough()’
I am struggling to see, where I went wrong. It seams easy, I followed Laravel instructions https://laravel.com/docs/5.4/eloquent-relationships#has-many-through , but clearly I need someone more familar with this sort of code as whenever I try to fetch $stagingsystem-stagesubtype I get error BadMethodCallExcep…