php - Laravel eloquent relationships with foreign keys -


stuck on 1 tonight...so i'm building messaging system comprised of tables seen in schema: http://www.laravelsd.com/share/8nbzmc

so user may post job user can send user message regarding job. triggers conversation created, message posted (containing id of user sent it) , 2 user_id's added conversation_user pivot table participants.

in terms of relationships job hasmany conversations belongsto user, conversation hasmany messages , belongsto job, messages belongto conversation etc etc etc.

my question based on schema, how show total number of messages relate job? i.e. how job id , filter conversations match id , count number of messages against each conversation? straying query builder land opposed eloquent? obvious solution add job_id messages table that's duplication , i'm stubborn :)

this should work:

$jobid = 1; $count = message::wherehas('conversation.job', function($q) use ($jobid){     $q->where('id', $jobid); })->count(); 

Comments

Popular posts from this blog

css - SVG using textPath a symbol not rendering in Firefox -

Java 8 + Maven Javadoc plugin: Error fetching URL -

datatable - Matlab struct computations -