I want to get job count for each user but i am getting the error Using $this when not in object context (View: C:xampphtdocsproject104resourcesviewsusersshow.blade.php). I will appreciate any help, Thanks in advance.
User model function
public function jobs()
{
return $this->hasMany(AppJob::class);
}
public static function getJobsCountAttribute(){
return $this->jobs()->count();
}
Job model
public function users()
{
return $this->belongsTo(AppUser::class);
}
In view file
@php
$getJobsCountAttribute = AppUser::getJobsCountAttribute();
@endphp
{{ $getJobsCountAttribute }}