// Запрос все коллекции
Project::with(..)
->withCount(..)
->orderBy(..)
->get()
// добавляем номер к элементам
->map(function ($item, $index) {
$item['number'] = $index + 1;
return $item;
})
// фильтруем по id авторизованного юзера
->where('user_id', $user->id);
->leftJoin('
Select
p1.product_ident_number
FROM products p1
LEFT JOIN warehouse_products wp ON wp.`product_id`=p1.id
LEFT JOIN orders o ON wp.`order_id`=o.id
WHERE wp.deleted_at IS NULL AND wp.stock_out_dt IS NULL AND wp.id IS NOT NULL
GROUP BY p1.product_ident_number)
AS temp_warehouse_amount'),
//AND (o.status != "' . Order::STATUS_SENDED . '" OR o.status IS NULL)
function ($query) {
/** @var JoinClause $query */
$query->on('products.product_ident_number', '=', 'temp_warehouse_amount.product_ident_number');
}
)
DB::statement('CREATE TEMPORARY TABLE projects_temp LIKE projects');
DB::statement('INSERT projects_temp SELECT * FROM projects');
$projects=Project::orderBy('lift_at', 'desc')
->get()
->map(function ($item, $index) {
$item['rank'] = $index + 1;
return $item;
});
foreach ($projects as $project)
{
// dd($project);
$project->update(['rank']);
}
Select
p1.product_ident_number
FROM products p1
LEFT JOIN warehouse_products wp ON wp.`product_id`=p1.id
LEFT JOIN orders o ON wp.`order_id`=o.id
WHERE wp.deleted_at IS NULL AND wp.stock_out_dt IS NULL AND wp.id IS NOT NULL
GROUP BY p1.product_ident_number)
AS temp_warehouse_amount
$projects=Project::with()
->withCount()
->orderBy('lift_at', 'desc')
->get()
->map(function ($item, $index) {
$item['ranking'] = $index + 1;
return $item;
})->where('user_id',Auth::id());
$projects=$this->paginate($projects, 10);
public function paginate($items, $perPage = 15, $page = null, $options = [])
{
$page = $page ?: (Paginator::resolveCurrentPage() ?: 1);
$items = $items instanceof Collection ? $items : Collection::make($items);
return new LengthAwarePaginator($items->forPage($page, $perPage), $items->count(), $perPage, $page, $options);
}