From 4b98711e07db0ac3f3cc31a60598a7ba5cf1669c Mon Sep 17 00:00:00 2001 From: Daniel Meltzer Date: Tue, 17 May 2016 23:31:57 -0500 Subject: [PATCH] Replace the assorted concat() methods with a full_name method in the User model and adjust queries accordingly --- app/Helpers/Helper.php | 23 ++++++++++----------- app/Http/Controllers/LicensesController.php | 3 +-- app/Models/User.php | 4 ++++ 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/app/Helpers/Helper.php b/app/Helpers/Helper.php index f2f9aba4d0..f8749c407e 100644 --- a/app/Helpers/Helper.php +++ b/app/Helpers/Helper.php @@ -164,11 +164,11 @@ class Helper public static function managerList() { - $manager_list = array('' => '') + User::select(DB::raw('concat(last_name,", ",first_name," (",username,")") as full_name, id')) - ->whereNull('deleted_at', 'and') - ->orderBy('last_name', 'asc') - ->orderBy('first_name', 'asc') - ->pluck('full_name', 'id')->toArray(); + $manager_list = User::where('deleted_at', '=', null) + ->orderBy('last_name', 'asc') + ->orderBy('first_name', 'asc')->get() + ->lists('full_name', 'id'); + return $manager_list; } @@ -187,13 +187,12 @@ class Helper public static function usersList() { - $users_list = array('' => trans('general.select_user')) + DB::table('users') - ->select(DB::raw('concat(last_name,", ",first_name," (",username,")") as full_name, id')) - ->whereNull('deleted_at') - ->where('show_in_list','=',1) - ->orderBy('last_name', 'asc') - ->orderBy('first_name', 'asc') - ->pluck('full_name', 'id'); + $users_list = User::where('deleted_at', '=', null) + ->where('show_in_list','=',1) + ->orderBy('last_name', 'asc') + ->orderBy('first_name', 'asc')->get() + ->lists('full_name', 'id'); + return $users_list; } diff --git a/app/Http/Controllers/LicensesController.php b/app/Http/Controllers/LicensesController.php index 5013317519..ef17637a3b 100755 --- a/app/Http/Controllers/LicensesController.php +++ b/app/Http/Controllers/LicensesController.php @@ -435,8 +435,7 @@ class LicensesController extends Controller } // Get the dropdown of users and then pass it to the checkout view - $users_list = array('' => 'Select a User') + DB::table('users')->select(DB::raw('concat(last_name,", ",first_name," (",username,")") as full_name, id'))->whereNull('deleted_at')->orderBy('last_name', 'asc')->orderBy('first_name', 'asc')->lists('full_name', 'id'); - + $users_list = Helper::usersList(); // Left join to get a list of assets and some other helpful info $asset = DB::table('assets') diff --git a/app/Models/User.php b/app/Models/User.php index 53bdcc6401..c24648b23b 100755 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -118,6 +118,10 @@ class User extends Model implements AuthenticatableContract, CanResetPasswordCon return "{$this->first_name} {$this->last_name}"; } + public function getFullNameAttribute() + { + return $this->first_name . " " . $this->last_name; + } /** * Returns the user Gravatar image url.