Questions tagged [eloquent]
Eloquent is an object-relational mapper (ORM) by and for Laravel. Use this tag for questions about using Eloquent within Laravel.
eloquent
27,300
questions
0
votes
0
answers
20
views
Laravel - Rollback specific eloquent transaction after many other transactions committed
I will try as much as I can to explain my question,
let's say that I have a shipping system that many admins using,
one of the shipping steps is to put a selected packages in a container,
the problem: ...
0
votes
0
answers
37
views
How to define a Many-to-Many Model relationship with itself in Laravel?
I'm working on a mini chat system and my main model is User.
Each User has many Contacts. A Contact is just another User in the system. A User can send an add request to the Contact which upon ...
0
votes
1
answer
35
views
How to Display Item Quantity Based on Product Selection in Laravel 11?
How to display the quantity of items from the 'item_amount' column when a product name is selected from the 'item_name' selector in Laravel 11, based on the data in the database?
Database
id
...
0
votes
1
answer
54
views
How can I do a join on the same table?
I came to a project where all kind of "characters" are in users table (for example, stores and sellers).
well, in the table exists (id, name, store) and others. In the database exists a &...
0
votes
0
answers
33
views
Laravel: How to insert entries into a specific table [duplicate]
There is an issue with inserting entries into a specific table.
Usual methodology (model)
Creation of an table (portfolio_item)
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\...
0
votes
0
answers
36
views
chain activities based on start/end date
I have an Timeline model with start and end timestamps (and other details).
I would like to create a relationship so I can jump to the next/previous activity.
They are not added sequentially, so I can ...
0
votes
2
answers
42
views
Laravel replaces the connection parameter with the default one
I have a model with a connection parameter to a different database.
class User extends Model
{
protected $connection = 'main_database';
}
When I save the model the connection is returning to ...
0
votes
1
answer
45
views
Return value must be of type Illuminate\Database\Eloquent\Relations\HasMany, Illuminate\Database\Eloquent\Builder returned
I had a method:
public function getAllVariants(): HasMany
{
return $this->hasMany(ProductVariant::class, 'product_id', 'id')->with(['product', 'attribute_values', 'image', 'description']);
}
...
1
vote
1
answer
41
views
Bug with Laravel Eloquent query buldier
I found a weird situation when nesting in a query a where with a orWhereNull.
The result is returning rows with values that are neither null nor correct
This is the code:
$query = Document::where(&...
0
votes
0
answers
88
views
Laravel query not returning correct values
I am building an expense managing web app.
I have a section analytics and I am working on filters for that page.
The filter parameters are sent to the server correctly, but the problem is that the raw ...
1
vote
0
answers
62
views
laravel take() returns empty collection for relationship
im trying to get 4 categories with only 4 articles in laravel using this code:
$categoryArticles = Category::whereHas('articles')->with(['articles' => function($q){
$q->select('id', '...
0
votes
1
answer
32
views
Laravel using a CASE which supplies data from a Subquery
I've been tasked with adding a new specific column to a report (sourced from a MySQL database) with criteria that returns a new column value based on conditions. It seems like the ideal use for a CASE ...
0
votes
0
answers
18
views
Mysql Left join with latest one record only from right table without turning off strict mode [duplicate]
I have 2 tables; I need join all cars and their users who has user.car_status = 1, but only with latest user.
I know it can be achived by turning off the above mode and there might be similar ...
1
vote
1
answer
53
views
How to properly use composite keys as the primary key in Laravel with Spatie Roles and Permissions package?
I need to use both email and phone_number as the primary key for the User model in my Laravel application. Since Laravel doesn't natively support composite primary keys, I found a workaround to ...
0
votes
1
answer
71
views
Declare aliases for counts which use the same column with Laravel's Eloquent method loadCount() [duplicate]
It is possible to load count of relations for already fetched model, like that:
$post->loadCount([
'comments',
'something',
'else',
]);
Now I want to add constraints to some counts:
$...