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
1 answer
35 views

Laravel Eager Loading tickets from DB

So I have the following relationship in my Model: Events Model: ...
0 votes
1 answer
56 views

Laravel controller getting results based on parameter including relationship results

I am trying to learn to improve my coding on a daily basis and this is one of the first times I am posting on here, so bear with me. I have two models, a Payment and an Expense model. A ...
  • 377
3 votes
1 answer
172 views

Optimization of laravel pivot table relationship

I have a pivot table called invite_riskarea which is designed as follows: This table stores the permissions that have a specific user (through an invite id) to ...
  • 147
1 vote
1 answer
102 views

A create gateway controller in Laravel

In my app users can create and soft-delete payment gateways something like Paypal. Users of a website can connect to the gateway and make payments. I've written the logic in a transaction also locking ...
1 vote
1 answer
156 views

Eloquent eager loading deep nested relation with "where" condition

is there a more elegant way to do what the code below does without use "foreach"? I am trying to load answers from questions but only the answers that contains a direct relation with an ...
1 vote
1 answer
127 views

Laravel CRUD Controller - code request

Here is my starting point for a laravel CRUD controller. I would appreciate it if someone could do a review and show me how an experienced developer would approach this. I do not want to progress with ...
2 votes
2 answers
199 views

'Lean controller'/'Business logic on service' and filtering, sorting, pagination methods on controllers

I'm currently reading about "Lean controllers"/"Business logic on services" and trying to refactor some legacy code. However I am struggling to apply what is taught in the ...
3 votes
1 answer
111 views

PHP Laravel Order generation Custom Class

Here is a custom class I use to handle different types of orders in Laravel. This question includes the code regarding Order Type A. I want to know whether I can simplify the code. I have different ...
  • 157
5 votes
1 answer
1k views

Laravel Scope get request data/param

I want to pass the param from the request on the scope method in the model and serve it as json to be rendered by select2. Which is better? 1. Pass request from the controller like this controller: <...
3 votes
1 answer
360 views

Get list and default value of columns of table with Eloquent

I use the below code to get a list of columns in a table, and assign the default value to the protected var $attributes in a Laravel Model. In this code, I use the DB function because I don't know ...
  • 131
1 vote
0 answers
34 views

what is the correct way to pass 3 where () conditions in the same function, multiple filters | eloquente - laravel

see: https://stackoverflow.com/questions/58882690/what-is-the-correct-way-to-pass-3-where-conditions-in-the-same-function-mult/58883277?noredirect=1#comment104033826_58883277 to better understand ...
1 vote
1 answer
469 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, ...
  • 247
1 vote
1 answer
77 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
1 answer
652 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 <...
  • 223
4 votes
2 answers
2k views

Full text search for multiple words using Laravel and MySQL

I'm using Laravel 5.6 and MySQL. I need to search multiple columns for a single word or multiple words (e.g., "camhandle", "cam handle"). The way I was originally doing it was just ...
4 votes
1 answer
93 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 ...
  • 41
1 vote
0 answers
205 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 ...
  • 945
4 votes
1 answer
746 views

Laravel Account models

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

Compare two tables and arrange the values in a new array

I have t things working with this current setup: ...
  • 223
1 vote
1 answer
162 views

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

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

Sending email notifications, each to a different set of subscribers

Here is a code which sends email notification on new comments. ...
5 votes
1 answer
858 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 ...
  • 96
1 vote
0 answers
351 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 ...
  • 63
1 vote
1 answer
69 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 ...
  • 818
2 votes
1 answer
107 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 ...
5 votes
1 answer
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
1 answer
140 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
1 answer
60 views

Compare 2 Different database Table

I have php function that compares two different database table. Any suggestion on improving it. ...
4 votes
2 answers
368 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
0 answers
737 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 ...
  • 530
4 votes
2 answers
6k 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,210
1 vote
1 answer
20k 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 ...
  • 1,210