0
Hello, in a certain process of my code I need to execute a query that returns me 4500 rows from the database
return Property::whereHas('portals', function ($query) {
$query->where('portal_id', '=', '1');
})->get();
After running this query I do a check on each line.
The problem is that before checking php accuses a memory error
PHP Fatal error: Allowed memory size of 16777216 bytes exhausted
In local environment I changed the memory_limit in php.ini to 512M and the function ran OK. The problem is that this is not a solution for me, that I will run it on online server.
I need to split this result before I run the check, but I don’t know how, someone can help me?
Did you limit the query? Making a query without limit is something unfeasible, it would be better to implement pagination.
– Guilherme Nascimento
How do I implement paging? I can’t put a limit on the query because I can have an infinite number of Properties
– Ivan Moreira
Ivan I’m tetando here, but I think you’ll have to use
::has
, however I will read the documentation and talk to a colleague, because I really do not understand of Eloquent (is that I use another framework)– Guilherme Nascimento