I want to count the number of reservation users made in admin panel using Laravel Datatables.
Reservation model
public function customer()
{
return $this->belongsTo(User::class, 'customer_id');
}
User model
public function reservations()
{
return $this->hasMany(Reservation::class);
}
public function getUsersCountAttribute()
{
return $this->reservations()->count();
}
Userdatatable
->editColumn('user_reservation', function(Reservation $reservation){
return $reservation->customer->users_count;
});
... However, - it throws an error saying:
Argument 1 passed to App\DataTables\Admin\UserDataTable::App\DataTables\Admin\{closure}() must be an instance of App\Models\Reservation, instance of App\Models\User given,
I tried following the steps mentioned in Counting total posts by a user in the blade view ... but it didn't help..
What am I missing?