Closed andrewdacenko closed 10 years ago
You mean you "only" get paginated data from the users table, or the paginated data includes both users and posts?
Yeap, paginate returns Only users data, no posts data included.
This has been fixed.
no not fixed, connection is lost when adding pagination
class Product extends Model
{
public function files()
{
return $this->belongsToMany(Files::class, 'entity_files', 'entity_id', 'file_id')->select(['files.path', 'entity_files.file_id']);
}
/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function category()
{
return $this->belongsTo(Category::class, '1c_cat_id', '1c_id');
}
/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function translations()
{
return $this->belongsTo(Translations::class, 'id', 'product_id');
}
/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function prices()
{
return $this->belongsTo(Prices::class, 'id', 'product_id');
}
/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function counts()
{
return $this->belongsTo(Remains::class, 'id', 'product_id');
}
/**
* @return \Illuminate\Database\Eloquent\Relations\HasManyThrough
*/
public function prisons()
{
return $this->hasManyThrough(
Prison::class,
Prices::class,
null, 'city_id', null
);
}
}
public function getAllProductTable($request)
{
$result = $this->startConditions()
->where('products.is_active', 1)
->with(['prisons', 'files', 'translations',
'prices' => fn($query) => $query->where('city_id', '=', $request->prisons_id),
'counts' => fn($query) => $query->where('controlled_count', '=', '1')->where('city_id', '=', $request->prisons_id)])
->orderBy('products.id', 'DESC');
return $result->paginate($request->perPage);
}
For example:
And in Country model we have:
If we search for all post in country like this
$country->posts
- we get the correct data, also using$country->posts()->take(10)->get()
- we also get right data fromposts
table.But if we call for
$country->posts()->paginate()
- we get paginated data fromusers
table.