Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # USER MODEL
- public function accounting()
- {
- return $this->hasMany('App\Accounting', 'userid', 'userid');
- }
- public function isOnline()
- {
- $usersAccounts = $this->accounting;
- return $lastAccount = $usersAccounts->last();
- if ($lastAccount) {
- return $lastAccount->rtype;
- }
- return 'oops';
- }
- # CONTROLLER
- $builder = App\User::with('accounting:rtype')
- ->ofType($filterRealm);
- return $datatables->eloquent($builder)
- ->addColumn('info', function (App\User $user) {
- $info = [];
- $info[] = $user->isOnline();
- return implode(' ', $info);
- })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement