Replace the assorted concat() methods with a full_name method in the User model and adjust queries accordingly

This commit is contained in:
Daniel Meltzer 2016-05-17 23:31:57 -05:00
parent 0e0b31bba6
commit 4b98711e07
3 changed files with 16 additions and 14 deletions

View file

@ -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;
}

View file

@ -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')

View file

@ -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.