Skip to content

Tag: laravel-5

query inside with eloquent

image address has location and total number of users. this query will return all the users and on relation whose query did not match will be null .I want to pull only those users which do not null value on relation and order By accordingly. Answer You can use whereHas condition

Import CSV data using Laravel

I’m trying to walk through as CSV file and extract all its contents. After the contents are imported I need to insert them into my mysql database table but before I can do that I need to check if these records exist. If a record does not, import this register. I’ve got headers and all content and I had created

Relationship eloquent in laravel?

In user: In post: I handle in controller: Then I get an array and the result returned is exactly what I need. But when I query this way because I need to get a lot of data, the result is an empty array. What did I do wrong? In UserController.php: Please give me any comments. Answer You have to select

Laravel Eloquent how to get relationship self object?

I have tables with below relationship And my HousingAdvertisement model has and HousingAdNearPlace when I make query like this: I got HousingAdNearPlace object in HousingAdvertisement model: How can I got self NearPlace model like this: Answer You need “Has Many Through” relationship on HousingAdvertisement And also define id keys as in ducumentation:

Transform nested collection in laravel

I have a nested collection that I want to transform, pulling some keys “up a level” and discarding some other keys. Every item in the collection has an allergens property. I need to make each items allergens property, look like I’ve tried the following: But it doesn’t overwrite the allergens property Answer Since you’re posting your collection as JSON, I