0

I've read tens of questions reporting this problem and in all of them the best answer was "increase your memory_limit". Fair enough, but here I have a memory_limit=128M and I'm trying to retrieve two lines, so I guess there's an error in the query.

This is the code in LampsController@create:

$families = DB::table('families AS f')
    ->join('products_families AS pf', 'pf.family_id', '=', 'f.id')
    ->join('products AS p', 'pf.product_id', '=', 'p.id')
    ->select(DB::raw('f.code'))
    ->where('p.category', '=', 'lamps');
// $families = Collection::unwrap($families);
print_r($families); exit;

The database schema is simple:

A) table families

----------------------------------------------
| id | code | name | created_at | updated_at |
|    |      |      |            |            |
----------------------------------------------

B) table products_families

---------------------------------------------------------
| id | product_id | family_id | created_at | updated_at |
|    |            |           |            |            |
---------------------------------------------------------

C) table products

-------------------------------------------
| id | category | created_at | updated_at |
|    |          |            |            |
-------------------------------------------

And this is the error I get:

Symfony \ Component \ Debug \ Exception \ FatalErrorException (E_UNKNOWN)
Allowed memory size of 134217728 bytes exhausted (tried to allocate 98570240 bytes)

What am I doing wrong?

8
  • 1
    why DB::raw('f.code')? Can you try with just simply 'f.code'? Commented Feb 27, 2018 at 11:13
  • 1
    First thing you have not added get() to get the result, you can do dd() or if you want to print you can use toSql() Commented Feb 27, 2018 at 11:15
  • @NikolaGavric You're right, I used DB::raw() because firstly I had in mind another query Commented Feb 27, 2018 at 11:17
  • You've resolved the issue? Commented Feb 27, 2018 at 11:18
  • @GaneshGhalame I spent half an hour concentrating on the query and the joins thinking the problem stood there, forgetting completely to add get(). Shame on me. Thank you Ganesh Commented Feb 27, 2018 at 11:19

1 Answer 1

4

Add get() to get the result of query, If you want to print query you can use toSql()

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.