Answer the question
In order to leave comments, you need to log in
How to count part of comment text in Eloquent?
Hello. In general, the question is described in the title, here I will just explain it a little. There is an "Article" model associated with a "Comment" model (one-to-many):
public function comments() {
return $this->hasMany('App\Comment')->orderBy('id', 'DESC');
}
Answer the question
In order to leave comments, you need to log in
public function comments() {
return $this->hasMany('App\Comment')->selectRaw('id, name, SUBSTRING(comment, 30) as comment_limit')->orderBy('id', 'DESC');
}
Why upload only a part? Make a Js handler, by clicking on the show link, another div will open, or the entire comment from a variable in Js or stored in a hidden div will be added there. And if you want Ajax, Eloquent has nothing to do with it. Just put substr() on the output
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question