I have here a laravel query:
DB::table('notifications')
->leftJoin('domains', 'domains.domain', '=', 'notifications.data->via_domain')
->select('notifications.data->via_domain as domain_name')
->groupBy('notifications.data->via_domain')
->get();
This shows domain names that exists between the tables 'notifications' and 'domains'. However, I want to count notifications.notifiable_id field in 'notifications' by:
DB::table('notifications')
->leftJoin('domains', 'domains.domain', '=', 'notifications.data->via_domain')
->selectRaw('count(notifications.notifiable_id), notifications.data->via_domain')
->get();
However it shows error in SQL syntax.
(You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near
via_domain from notifications left join domains on
domains.domain = not at line 1 (SQL: select
count(notifications.notifiable_id), notifications.data->via_domain
from notifications left join domains on domains.domain =
notifications.data->'$."via_domain"')')
Thanks for the help, minna-san.


data->via_domainactually within the table or is this a variable? Can you post the two tables you're joining