0
Я пытаюсь в течение трех дней передать это отношение из Laravel query_builder в Laravel eqloquent. Но это выглядит бесполезным:Изменение отношения базы данных к Laravel eloquent
$category_products = DB::table('products')
->Join('categories', 'products.category_id', '=', 'categories.id')
->select('products.*', 'categories.CategoryEnName')
->where('categories.parent_id', '=', '2')
->get();
код выше работает хорошо, но это не работает с Laravel "пагинацией", как это:
$category_products = DB::table('products')
->Join('categories', 'products.category_id', '=', 'categories.id')
->select('products.*', 'categories.CategoryEnName')
->where('categories.parent_id', '=', '2')
->get()->paginate(15);
That'smy категории Модель:
class Category extends Model
{
protected $guarded = ['id'];
//For the nested "tree like" categories
public function parent()
{
return $this->belongsTo('App\Category', 'parent_id');
}
//For the nested "tree like" categories
public function children()
{
return $this->hasMany('App\Category', 'parent_id');
}
/**
*
*Grab all the products belong to this category
*
*/
public function products()
{
return $this->hasMany('App\Product');
}
я хочу, чтобы изменить код из построителя запросов на Laravel eloquent?