Skip to content

Tag: laravel

Laravel using where clause on a withCount method

I am trying to do a where clause on withCount method of laravel’s eloquent query builder using this piece of code. and this code is giving me this error. SQLSTATE[42S22]: Column not found: 1054 Unknown column ‘upvotes_count’ in ‘where clause’ (SQL: select , (select count() from u…

Laravel: getting a single value from a MySQL query

I’m trying get a single value from MySQL database using laravel but the problem I’m getting an array . this is my query result in MySQL command line: my laravel function: expected $data value is a string with value= Admin but what i get is : [{“groupName”:”Admin”}] Answer E…

Laravel – seeding large SQL file

A memory exhaustion happens when I run my DB seed script in production. Below is my seed script. So what I did was add a no-limit on my seed script. The problem now is that when I run the script it logs the output into the terminal the content of the SQL script (which is very, very big). Is there

Counting related rows in a child table

I have been trying to do some queries and getting a count on related tables using eloquent. Tables: requests contact (belongs to requests) history (belongs to contact) As such X number of requests each have Y number of contacts which in term each have Z number of histories Using sql I can do something like th…