我在名为ReportsServiceProvider的模块中有一个提供程序。我试图从所有视图访问数据,但是我没有得到我想要的项目。下面的查询在控制器中运行良好,但在提供程序中失败。 我的代码如下:
public function boot()
{
{
view()->share('invoices', function () {
$builder = DB::table('invoice_items')
->select(
[
DB::raw("DISTINCT invoice_items.uuid"),
'invoices.number AS invoice_number',
'invoices.date_closed',
'invoice_items.name AS service_name',
'invoice_items.total_amount',
'invoice_items.amount_paid',
'invoice_items.balance',
'visits.created_at',
'payment_mode_visits.payment_mode',
'visits.id AS visit_id',
'visits.ended_at',
'clinics.name',
'patients.first_name',
'patients.last_name',
]
)
->join('invoices', 'invoices.id', 'invoice_items.invoice_id' )
->join('visits', 'visits.id', 'invoices.visit_id')
->join('patients', 'patients.id', 'visits.patient_id')
->join('clinics', 'clinics.id', 'visits.clinic_id' )
->leftJoin('payment_mode_visits', 'payment_mode_visits.visit_id', 'invoices.visit_id')
->where('invoice_items.amount_paid', '>', 0);
return $builder->get();
});
}
}
当我以任何视图转储$invoices
时,我都会得到这个
Closure() {#1016 ▼
class: "Modules\SouthLakeAnalytics\Providers\ReportsServiceProvider"
this: Modules\SouthLakeAnalytics\Providers\ReportsServiceProvider {#193 …}
file: "/var/www/html/medyq-web-core/modules/SouthLakeAnalytics/Providers/ReportsServiceProvider.php"
line: "42 to 72"
}
我做错了什么?