Last active
June 26, 2016 21:58
-
-
Save pi0/1207d734c63ce86622e8ff2f393229cd to your computer and use it in GitHub Desktop.
Laravel Mongo User Model
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App; | |
use Illuminate\Auth\Authenticatable; | |
use Illuminate\Auth\Passwords\CanResetPassword; | |
use Illuminate\Contracts\Auth\Access\Authorizable as AuthorizableContract; | |
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract; | |
use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract; | |
use Illuminate\Foundation\Auth\Access\Authorizable; | |
use Jenssegers\Mongodb\Eloquent\Model as Model; | |
/** | |
* User | |
* The User Model | |
* @mixin \Eloquent | |
* | |
* @property integer $id | |
* @property \Carbon\Carbon $created_at | |
* @property \Carbon\Carbon $updated_at | |
* | |
* @property string name | |
* @property string email | |
* @property string mobile | |
* @property string password | |
* | |
*/ | |
class User extends Model implements | |
AuthenticatableContract, | |
AuthorizableContract, | |
CanResetPasswordContract | |
{ | |
use Authenticatable, Authorizable, CanResetPassword; | |
/** | |
* 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', | |
]; | |
public function getAvatarAttribute($attr) | |
{ | |
if ($attr) | |
return $attr; | |
else | |
return '//www.gravatar.com/avatar/' . md5($this->email).'?d=retro'; | |
} | |
public function getNickAttribute($attr) | |
{ | |
if ($attr) | |
return $attr; | |
else { | |
$e = explode(' ', $this->name); | |
if (count($e) > 0) | |
return str_replace('_',' ',$e[0]); | |
else | |
return null; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment