Skip to content
Advertisement

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 receiving the value of the primary key easily without knowing

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 where on relationship object

I’m developing a web API with Laravel 5.0 but I’m not sure about a specific query I’m trying to build. My classes are as follows: and Now, I want to get all the events with a specific participant. I tried with: but the where condition is applied on the Event and not on its Participants. The following gives me an

Laravel 5 Eloquent appending relationships to JSON on multiple levels

So it is pretty easy to include relationships on models such as: when there’s a get request to the user resource, it will include associated roles automagically. But in this setup, the role resources returned with user resource also includes it’s own included relationships like: This generates huge objects, that mostly include unnecessary related child models. I can workaround this

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: What am

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/framework/blob/4.2/src/Illuminate/Database/Query/Builder.php

Advertisement