T
T
tushev2020-07-02 16:15:41
Laravel
tushev, 2020-07-02 16:15:41

How to use Laravel Eloquent Relationships with complex queries?

Is it possible to create a model that does not have a table associated with it? For example, you often want to have a complex SQL query with group by, joins, etc. as a record source. As a partial solution, I used the Database View.

Sometimes you generally want to create records in PHP without accessing the database. I also want to use scopes to pass some parameters.

In other words, in the definition of the model, instead of a simple $this->hasMany(....), I want to cram some kind of complex SQL query with parameters, or not use a database call at all.

Of course, using save() on such related models is no longer possible, but I want to use such models in relay chains.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Aksentiev, 2020-07-02
@Sanasol

What is the question? For this, there is a Query Builder, in which you can do anything, relations have nothing to do with it and exist in parallel.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question