Advertisement
Guest User

Untitled

a guest
Jan 30th, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.72 KB | None | 0 0
  1. # USER MODEL
  2.    public function accounting()
  3.     {
  4.         return $this->hasMany('App\Accounting', 'userid', 'userid');
  5.     }
  6.  
  7.     public function isOnline()
  8.     {
  9.         $usersAccounts = $this->accounting;
  10.  
  11.         return $lastAccount = $usersAccounts->last();
  12.         if ($lastAccount) {
  13.             return $lastAccount->rtype;
  14.         }
  15.         return 'oops';
  16.     }
  17.  
  18. # CONTROLLER
  19.  
  20.         $builder = App\User::with('accounting:rtype')
  21.         ->ofType($filterRealm);
  22.  
  23.         return $datatables->eloquent($builder)
  24.             ->addColumn('info', function (App\User $user) {
  25.                 $info = [];
  26.  
  27.                 $info[] = $user->isOnline();
  28.  
  29.                 return implode(' ', $info);
  30.             })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement