Skip to content

Instantly share code, notes, and snippets.

@herusdianto
Created May 12, 2015 15:10
Show Gist options
  • Save herusdianto/71f85d05e51f483c5761 to your computer and use it in GitHub Desktop.
Save herusdianto/71f85d05e51f483c5761 to your computer and use it in GitHub Desktop.
Laravel Eloquent lists multiple column.
<?php namespace App;
use DB;
use Illuminate\Auth\Authenticatable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Auth\Passwords\CanResetPassword;
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract;
class User extends Model implements AuthenticatableContract, CanResetPasswordContract {
use Authenticatable, CanResetPassword;
/**
* The database table used by the model.
*
* @var string
*/
protected $table = 'users';
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = ['name', 'email', 'password'];
/**
* The attributes excluded from the model's JSON form.
*
* @var array
*/
protected $hidden = ['password', 'remember_token'];
/**
* get first name and last name
*/
public static function getFullName()
{
return self::select(DB::raw("CONCAT(first_name, ' ', last_name) AS full_name, id"))->lists('full_name', 'id');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment