Questions tagged [eloquent]

Eloquent is Laravel's own object-relational mapper. It is named "Eloquent" because it allows you to work with your database objects and relationships using an eloquent and expressive syntax.

Filter by
Sorted by
Tagged with
1
vote
1answer
151 views

PHP Laravel - Improving and refactoring code to Reduce Queries

Improve Request to Reduce Queries I have a web application, where users can upload Documents or Emails, to what I call a Strema. The users can then define document fields email fields to the stream, ...
1
vote
0answers
36 views

A PHP Controller, which feels to 'array-like', in Laravel

This is a controller, which receives the validated input from a http request, then finds the assorted model and for each translation key in the received data, it will add it to the model. ...
2
votes
1answer
200 views

Retrive relation on a polymorphic model

I have a Game model that is "static". Containing game information and such, and users can comment on all games. Games model <...
4
votes
1answer
81 views

Users adding each other in Laravel

I'm looking for a code review for the following system that I created. It allows a landlord, to add a tenant to start a tenancy. It has added, accept, reject, and prohibits a tenant from adding ...
1
vote
0answers
188 views

Replacing a substring in a table

I am using DB::table to search through a table that has a field called 'data' that has a substring ...
3
votes
0answers
398 views

Laravel Account models

This library is part of accounting system. Two major models are involved. For every transaction there is an entry in AccountTransaction model and corresponding 2 ...
0
votes
1answer
708 views

Compare two tables and arrange the values in a new array

I have t things working with this current setup: ...
1
vote
1answer
130 views

Laravel - super long relation, it doesn't feel right

Okay, This is my method: ...
1
vote
1answer
85 views

Sending email notifications, each to a different set of subscribers

Here is a code which sends email notification on new comments. ...
4
votes
1answer
609 views

Laravel Pagination with haversine formula in it

I'm using the haversine formula to count distance from selected post-code to desired destination. I have the following scope in ...
1
vote
0answers
306 views

Extend the Laravel Eloquent model in order to easier implement CRUD REST for my routes

By extending the Model and using this inside my routefiles, I can easily call these functions inside the corresponding HTTP ...
1
vote
1answer
54 views

Phishing Project - Refactor Using Models

After receiving some good feedback on the previous question, I've refactored my database and have begun to refactor the associated code. As a result of implementing models for all tables in the ...
2
votes
1answer
95 views

Database query with Eloquent

I have got two tables articles and tags in the database. My goal was to retrieve all fields from articles table and one category field from tags table with Eloquent. I couldn't do this so instead I ...
4
votes
1answer
1k views

Eloquent methods to calculate the average rent of apartments

I am working on a Laravel 5.1 website where I am counting the average rent of apartments in a specific area. Besides of that I want to get the average rent by amount of rooms in the apartment. The ...
1
vote
1answer
127 views

Method on Laravel model to find courses related to a course

I have a Laravel project that has courses. I want to take the related courses from one. Should I create the method in the model (the php class) or in the controller? Currently I have this code in ...
0
votes
1answer
54 views

Compare 2 Different database Table

I have php function that compares two different database table. Any suggestion on improving it. ...
4
votes
2answers
347 views

4 database queries, multiple loops in loops, slow processing time

The octoberCMS(based on laravel) controller below is what I use to select the lowest price in 4 pricelists in the given daterange. Prices can vary and it's not guaranteed that the more expensive ...
2
votes
0answers
665 views

Extended Laravel Eloquent models to add filters to model setters

One of the tasks I find myself doing repeatedly is to filter the incoming inputs that will be stored in models. Examples of this include trimming, removing repeated or unnecessary pre/suffixes, commas ...
1
vote
0answers
52 views

Eloquent Scope and Normal Way

I read the documentation part of Eloquent, especially scopes: Scopes allow you to easily re-use query logic in your models. To define a scope, simply prefix a model method with scope: And so, with ...
3
votes
2answers
4k views

Effective usage of multiple joins in Eloquent dependent on variable

I have an Eloquent model that has multiple types of joins that is used to filter out different request to grab the data of movies e.g.: Actors, ...
1
vote
1answer
19k views

Optimizing Laravel Eloquent multiple joins

The following is working and readable SQL for Eloquent that I have created. The downside is that it looks more like a 1:1 with SQL and I don't think I'm using the full potential of Eloquent. I thought ...