Skip to content

Tag: eloquent

Get primary key of Eloquent model instance

I’m happy enough to work on a project with (not) very consistent column names in our MySQL database. We have camelCase, PascalCase, ‘Id’, ID and it’s driving me nuts. I’ve decided to start using Eloquent in our application (which is NOT Laravel). I would love to have a method of …

Laravel Eloquent hasMany relationship

Hi I am new to Laravel and currently in am using Laravel 4.2. I am trying to create an application where I have users, posts and comments table and have the following model User Model Post Model Comment Model What I want to achieve : user’s Post and comment for Post What I have done So far::: I am able

Laravel, how to ignore an accessor

I have a model with a custom accessor so I get that custom attribute, But now, in one case, I need to get only some fields, without this OrderContents one. But doing it this way, it returns me the OrderContents as well.. is there a way to not get that field? Thanks! Answer There’s no way to do it in

Laravel belongsTo returning null when using ‘with’

I’m just getting started with Laravel so please forgive any noobness. I have a User and Order model, a user has many orders: So I think I have the above right. But when I do this: I get Call to a member function addEagerConstraints() on null. However, if I do it the other way around, it works great: Wha…

Laravel Simple Month Selection

y tried retrieve month from date field “fechas” (datetime type) where testing with SQL clause MONTH not works… thanks for replies Answer You could use the hide gem whereMonth: I highly recommend to you read the Builder.php source to search for another gems. 🙂 https://github.com/laravel/frame…