Quantumass soufiane Quantumass soufiane - 6 months ago 26
PHP Question

sort w/ left join laravel

I want to join the row (subcomment) that has the max marks so I tried this

$comments=$comments->leftJoin('sub_comments', function($join){
$join->on('comments.id', '=', 'sub_comments.comment_id');
$join->where('sub_comments.marks', '=', function($q){

and I get this

Object of class Closure could not be converted to string

is there any way I can do this? I appreciate any helpful answer, thanks in advance.


I solve it by adding a hasMany relationship to the Model of the comments then I sorted the sub_comments ( second table «right table» ) inside the model like that

return $this->hasMany('App\SubComment')->orderBy('sub_comments.marks');

and it is working good