1,021 questions
0
votes
0
answers
50
views
Defining a BelongsToMany relation with an additional where clause
I have a belongs to many relation between two tables via a pivot table. But the business dictates that the relation needs an additional WHERE clause connecting the first with the last table.
table_a ...
0
votes
0
answers
50
views
Using Select on a has_many_trough relationship from filamentphp on pgsql
Am working with laravel 11 with filamentphp 3 on postgres db, I have a schema for Authors, Profiles, Posts and post_has_author.
author(author_id, profile_fk,...)
profile(profile_id,...)
post(post_id,.....
-1
votes
1
answer
48
views
Laravel 10 Eloquent. Morph fields type error
I`m using postgres 17.2
I have transactions table with morph columns entity_type and entity_id. When i use whereHasMorph i got a type error with entity_id because users table id is bigint
Example:
$...
4
votes
3
answers
160
views
Laravel 12 relation MorphTo with unknown type value
I'm trying to use Polymorphic Relationships from this docs https://laravel.com/docs/12.x/eloquent-relationships#polymorphic-relationships
I have model Balance
class Balance
{
public $subject;
...
-1
votes
1
answer
67
views
Laravel query model with relations, I just want the related models that meet criteria
I have a model salesperson, it has model traffic related. I am trying to return all the salespeople with traffic in a given month and get ONLY the traffic from that month.
Right now it is returning ...
2
votes
1
answer
45
views
How can I use the same condition for separately summing colomns?
In my Laravel project. I have model named Section. Each section has a hasMany relation to the Student model with the function studentsInCurrentSession and each student has a hasMany relation to the ...
1
vote
1
answer
35
views
model the inverse of hasManyThrough relationship using a pivot model
I have the following models/tables:
branch:
id - integer
department:
id - integer
teacher:
id - integer
branch_department_id - integer
branch_department:
id - integer
...
0
votes
1
answer
74
views
Saving a Post and a Video into a relational model using Laravel eloquent
I have created a migration name savables as follows, the goal is to attach, and detach the post_id or video_id along with its model type.
Schema::create('savables', function (Blueprint $table) {
$...
0
votes
2
answers
65
views
Custom Intermediate Table Models - eager loading
Here is my current setup:
<?php
namespace App\Models;
use Exception;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\...
1
vote
1
answer
45
views
Laravel Eloquent Query Using Case/When to apply conditions dynamically
I am trying to apply a different set of date filter depending on the values of the start_date and end_date column of the robot table
Condition
If robot start date && robot end date are both ...
0
votes
0
answers
43
views
Why doesn’t Eloquent with() load related data when using join on a morphOne relationship?
I'm working with Laravel Eloquent and attempting to load related data using with() alongside a left join, but I'm running into issues. Specifically, I have a Company model with a morphOne relationship ...
-1
votes
1
answer
239
views
Attempt to read property "name" on null, Laravel 11
I find this error on local development machine. I can see the details of this in the database but when i try to list all the jobs it breaks. So I think it is a something in a way database objects are ...
0
votes
1
answer
61
views
How to get the last entry of a Laravel model which is not NULL on a certain column (Laravel 11)
I would like to get back within a with() the last entry of a modal which is not null on a certain column.
I know that it is possible to simply get the last entry with the following function in the ...
0
votes
1
answer
25
views
eloquent searching laravel
I created a search feature in the disposition table.
The initial display is in accordance with the eloquent that I set. but when I change the value of search , the where clause that I set cannot work ...
3
votes
2
answers
70
views
Laravel Many-to-Many Relationship giving wrong result
I am developing a database for giveaways. I have two main tables: participants and giveaways with an N:N relationship since a participant can participate to one or more giveaways and a giveaway can ...
-3
votes
3
answers
190
views
Laravel relationships with extended models
I've got a requirement for a set of models with the same database table, but they need to implement certain methods in a different way. Given a set of classes like this:
class Item {
protected $...
0
votes
1
answer
91
views
how to get data from the relationship table in laravel 10?
How do I get the data from a relationship table?
this is the tables' structure:
paradises
id - integer
title - string
travel_interest_id - integer
travel_interests
id - integer
...
1
vote
1
answer
174
views
In filamentphp, how to fill the fields of a form with the login user profile data?
I'm working with Filamentphp, and I've created a "Report" resource. When creating a Report I want to automatically fill in data from the logged in user to the form.
Forms\Components\...
0
votes
1
answer
59
views
Eloquent ORM performance with subqueries for relational models
Laravel eloquent uses subqueries for relationship model instead of joins as joins offer more optimal performance .How does eloquent orm ensures performance for relational models ?
3
votes
0
answers
1k
views
How to show database json column values in filament php table
I have a json column in my database table which stores the foreign keys, the field name is cast as array on the model. I am using multiple select with a relationship and the record get saved as ...
0
votes
1
answer
194
views
How to Create Conditional BelongsTo Relationships in Laravel Models?
I need to set up conditional belongsTo relationships. Specifically, I have ModelA that can belong to either ModelB or ModelC based on a column value (related_id). For example, if related_id is 1, it ...
-1
votes
1
answer
61
views
laravel polymorphic relation with custom FK in related models
Here is what the table might look like
Store
id
modelable_id
modelable_type
name
other columns
Shoe
id
sole_id (FK)
other columns
Cloth
id
jean_id (FK)
other columns
Bag
id
cover_id (FK)
other ...
0
votes
1
answer
51
views
Laravel relation based on column from main table
So this is the query I have constructed so far
$data['requested_units'] = RequestedUnit::with([
'user',
'agent_warrants' => function ($q) {
$q->where('type', RequestedUnit::...
1
vote
1
answer
102
views
Laravel Eloquent: belongsToMany to return an array of strings instead of array of objects
I have two tables that are connected with a pivot table.
shows:
+----+--------+
| id | show |
+----+--------+
| 1 | show1 |
| 2 | show2 |
| 3 | show3 |
+----+--------+
draft_types:
+----+-----...
0
votes
2
answers
52
views
Laravel where condition within 'with'
I have an eloquent query:
$cameras=Jump::Video()
->with('flight','flight.aircraft','flight.airfield')
->with('student','student.logininfo','student.logininfo....