我有一个要传递给我的视图的集合。有3行:
Collection {#869 ▼
#items: array:3 [▼
0 => Customer {#868 ▼
#table: "customers"
#guarded: []
#connection: "mysql"
#primaryKey: "id"
#keyType: "int"
+incrementing: true
#with: []
#withCount: []
#perPage: 15
+exists: true
+wasRecentlyCreated: false
#attributes: array:10 [▼
"id" => 17
"business_id" => 1
"first_name" => "Bob"
"last_name" => null
"email" => null
"phone" => null
"sent_at" => null
"created_at" => "2017-10-03 16:18:30"
"updated_at" => "2017-10-03 16:18:30"
"deleted_at" => null
]
#original: array:10 [▶]
#changes: []
#casts: []
#dates: []
#dateFormat: null
#appends: []
#dispatchesEvents: []
#observables: []
#relations: []
#touches: []
+timestamps: true
#hidden: []
#visible: []
#fillable: []
}
1 => Customer {#867 ▶}
2 => Customer {#866 ▶}
]
}
在这 3 个客户中,其中 1 个有一个“sent_at”列,我想在我的视图中计算该列。我知道您可以在控制器中执行此操作,但我想修改视图中的集合。
我在我看来已经尝试过了,它没有返回任何结果:
$customers_pending = $customers_all->where('sent_at', null);
$customers_pending->count();
dd($customers_pending);
我想我没有完全理解集合并修改它们。$customers_pending 应该返回 = 1
我得到:
Collection {#879 ▼
#items: []
}