$articles = `SELECT category, id, title FROM (
SELECT c.name AS category, a.id, a.title, row_number() OVER (PARTITION BY categoryid ORDER BY a.sort DESC) AS row
FROM articles a INNER JOIN categories c ON (a.categoryid=c.dboid)
ORDER BY c.sort
) AS foo WHERE row <= 5;
foreach ($categories as $category) {
category->load(['news' => function($q){
$q->take(5);
}]);
}
$articles = `SELECT category, id, title FROM (
SELECT c.name AS category, a.id, a.title, row_number() OVER (PARTITION BY categoryid ORDER BY a.sort DESC) AS row
FROM articles a INNER JOIN categories c ON (a.categoryid=c.dboid)
ORDER BY c.sort
) AS foo WHERE row <= 5;
foreach ($users as $user) {
user->load(['posts' => function($q){
$q->take(5);
}]);
}
@foreach ($client->relatedOrders as $order)
@foreach ($order->relatedProducts as $product)
@php($a[] = $product->qty*$product->relatedPenalty->price)
@endforeach
@endforeach
в представлении$client->getTotalOrdersProductsPenaltyPrice()
trait UUID
{
protected static function boot()
{
parent::boot();
$model->setIncrementing(false);
static::creating(function (Model $model) {
$model->{$model->getKeyName()} = Str::orderedUuid();
});
}
}
File::where('type', $type)
->whereHas('products', function ($query) {
$query->where('slug', '=', $product_slug);
})
->first();
или
File::select('files.*')
->leftJoin('products' ... условия джоина)
->where('files.type', $type)
->where('products.slug', $product_slug)
->first();