Skip to content
Advertisement

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.1, updated_at = 2018-01-12 15:26:47 where id is null) Why is

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: However, this is obviously not very

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 it add a line into the eloquent to make

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 in my examples with regards to which can change

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 BadMethodCallException with message ‘Call to undefined method >IlluminateDatabaseQueryBuilder::hasManyTrough()’ Can someone help? StagingSystems StageName StageSubType MODELS StagingSystem StageName StageSubType Answer You

Advertisement