You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
My idea is how to use paging in the Eloquent model [hasMany]?
For example, I have Article model, Comment model, Article model needs to be associated with Comment model to get the comments of the article; so is there a way to implement paging query for Comment?
The comments method of the Article model:
public function comments()
{
return $this->hasMany('App\Models\Comment','artiid','id');
}
Controller, get article details
public function detail($id = null){
$id = settype($id,'int');
$data = Artical::where('id',$id)->first();
return view('pages.article.detail',compact('data'));
}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
My idea is how to use paging in the Eloquent model [hasMany]?
For example, I have Article model, Comment model, Article model needs to be associated with Comment model to get the comments of the article; so is there a way to implement paging query for Comment?
The comments method of the Article model:
public function comments()
{
return $this->hasMany('App\Models\Comment','artiid','id');
}
Controller, get article details
public function detail($id = null){
$id = settype($id,'int');
$data = Artical::where('id',$id)->first();
return view('pages.article.detail',compact('data'));
}
Beta Was this translation helpful? Give feedback.
All reactions