I need to sum every paid_amount inside of each expense_payment_liab instead of returning all these
individual paid_amount as it can be seen in images for clear view.So far my query looks like this:
Model Relation is like Voucher has many Expenses and Expenses has many Expensepaymentliab.
我需要计算状态为X的人,其中有多个项目。 模型:人员、项目、状态 People->items() = belongstomany with item_people table as intermediate
Items->statuses() = belongstomany with item_statuses table as intermediate People::with(['items','items.statuses' => function ($q){
$q->whereIn('
所以我有一个查询,我想要在模型上选择特定的列和关系计数。 像这样的东西 $posts = Post::withCount('comments')->select('title', 'content')->get();
foreach ($posts as $post) {
$post->comments_count // this is not available because of select in query
} 现在,当我在查询中使用select时,comments_count不再可用。在模型上有$appe
我希望withCount包含不存在的关系的计数。 例如,假设我有一个名为people的表和一个名为pets的表。 people有多个pets,但pets可以有一个空people_id。我想要获得每个people的pets的计数,但我还想包括没有people_id的pets。 我知道我可以简单地执行People::withCount('pets')->get(),但这不包括people_id为空的pets的计数。 我正在寻找的结果将类似于: person_name | pets_count
John | 2
Mike | 3
Joan
我有一篇文章,喜欢和评论模型
我想得到文章的数据,评论数据和喜欢的计数在一个帖子使用关系在拉拉。
一切都正常,但是从下面的代码中,我得到了喜欢数组,我希望计数没有任何循环。这种关系有可能吗?
这是我的带有关系的PostController代码:
$posts = Post::with('user','comment')->get();
职位模式:
public function comment(){
return $this->hasMany(Comment::class);
}
public function like(){
re
我有点担心拉拉维尔模型的循环问题。我有三个相互关联的表,其中一个应该被孩子圈起来,并显示其他表的关系,那么这里的交易是什么?
我有三张桌子:
categories
- id
- parent\_id = relation to the same table foreign id
- name = string
threads
- id
- category\_id = relation with categories
- title
- desc
posts
- id
- category\_id = to make query easier
- thread\_id = relation w
我正在尝试将我的sql查询转换为Laravel查询
SELECT products.name,
(SELECT SUM(orders.date BETWEEN from_date AND to_date)
FROM orders WHERE orders.product_id = products.id ) as order_counts
FROM products;
然后,我尝试将其转换为,但结果出现了一个错误:
Product::select('name',
DB::raw("SUM(orders.date
BETWEEN $request->from_d
我是Laravel的新手,我遇到了以下问题:我有一个用于用户和组的表,以及一个用于连接它们的表。任何用户都可以加入任何组的一般任务。
----------------------------------------------
| users | groups | user_groups |
|--------------------------------------------|
| id - int pk | id - pk | id - pk |
| name text | name | user_id - fk
在我的应用程序中,我有一个很长的类别列表。我用以下代码加载它们:
$categories = Categories::all();
在Categories中有这样一个函数:
public function transactions()
{
return $this->hasMany(Transactions::class);
}
public function getPreviousActivityAttribute() {
return $this->transactions()
->where('date', '&
我正在使用Laravel进行一个小项目,现在我在HTML表中显示我在数据库中的产品。
所以现在我已经创建了另一个名为变体的数据库表,用于存储产品variants,。
我想要count the number of variants,对于each product,这是我的代码:如您所见,我也选择了categories, brands, suppliers,我想要计算variants的数量(因为我已经有了一个名为variants,的表,包含product_id字段)
public function index()
{
$products = Product::with(['categ
我有两个拉拉维尔雄辩的模型,Product和ProductCategory与belongsTo()的关系,名为Category()从产品到ProductCategory。
我已经有模型集合迭代在显示刀片中的@foreach循环,但希望能够根据Category()关系得到产品数量的计数.
IE:在收集的20款车型中,可能有5款汽车、5台变速箱和5款Acme小部件。我试图找到一种方法来输出作为结果一部分返回的类别列表,以及与每个返回类别相关的记录数量。
产品模型
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
c
我有一个数据库设置,你有一个讲师,有很多组,每个小组有很多学生,一个学生也可以在很多组。因此,我在讲师和小组之间有一对多的关系(分别),在学生和团体之间有很多到很多的关系。
我想给讲师看看他们有多少学生。例如,如果讲师有5个小组,每个小组有5个学生,那么我想展示25个。我试过这个auth()->user()->userable->groups()->withCount('students')但是我得到了这个:
调用null上的成员函数getRelationExistenceCountQuery()
编辑,下面是关系:
# user model
c
在Laravel 9中,我试图将子查询的结果添加到查询中(因为没有更好的措辞),我被卡住了。更具体地说,我正在尝试加载所有产品,同时添加关于当前用户是否购买了该产品的信息。
我为什么要这么做?我目前正在加载所有产品,然后加载所有购买的产品,然后比较2,以确定用户是否购买了产品,但这意味着额外的查询,我想避免。为了这个问题假装不存在分页(因为当分页时,多个查询的影响会大大减少)。
两个表users和products之间有很多到多个关系,因此在模型上定义了这些关系:
public function products()
{
return $this->belongsToMany(Pr
在我的Laravel项目中,我有以下模型
商家
交易
成交票
交易点击
交易类型
商人评级
这就是我的招商模型
class Merchants extends Model
{
//
public function deals()
{
return $this->hasMany('App\Deals', 'merchant_id', 'merchant_id');
}
}
交易模型
class Deals extends Model
{
//
public