Attendize/app/Models/User.php

159 lines
3.3 KiB
PHP
Raw Normal View History

2016-03-05 00:18:10 +00:00
<?php
namespace App\Models;
2016-02-29 15:59:36 +00:00
use Illuminate\Auth\Authenticatable;
use Illuminate\Auth\Passwords\CanResetPassword;
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract;
2016-03-05 00:18:10 +00:00
use Illuminate\Database\Eloquent\Model;
2016-02-29 15:59:36 +00:00
use Illuminate\Database\Eloquent\SoftDeletes;
2016-03-05 00:18:10 +00:00
class User extends Model implements AuthenticatableContract, CanResetPasswordContract
{
2016-02-29 15:59:36 +00:00
use Authenticatable, CanResetPassword, SoftDeletes;
/**
* The database table used by the model.
*
* @var string
*/
protected $table = 'users';
2016-03-14 16:37:38 +00:00
/**
* The attributes that should be mutated to dates.
*
* @var array $dates
*/
2016-03-09 22:05:39 +00:00
public $dates = ['deleted_at'];
2016-03-14 16:37:38 +00:00
2016-02-29 15:59:36 +00:00
/**
* The attributes excluded from the model's JSON form.
*
* @var array
*/
2016-03-05 00:18:10 +00:00
protected $hidden = ['password'];
2016-02-29 15:59:36 +00:00
2016-03-14 16:37:38 +00:00
/**
* The attributes that are mass assignable.
*
* @var array $fillable
*/
2016-03-09 22:05:39 +00:00
protected $fillable = [
'account_id',
'first_name',
'last_name',
'phone',
'email',
'password',
'confirmation_code',
'is_registered',
'is_confirmed',
'is_parent',
'remember_token'
];
2016-03-14 16:37:38 +00:00
/**
* The account associated with the user.
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
2016-03-05 00:18:10 +00:00
public function account()
{
2016-02-29 15:59:36 +00:00
return $this->belongsTo('\App\Models\Account');
}
2016-03-14 16:37:38 +00:00
/**
* The activity associated with the user.
*
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
2016-03-05 00:18:10 +00:00
public function activity()
{
2016-02-29 15:59:36 +00:00
return $this->hasMany('\App\Models\Activity');
}
/**
* Get the unique identifier for the user.
*
* @return mixed
*/
2016-03-05 00:18:10 +00:00
public function getAuthIdentifier()
{
2016-02-29 15:59:36 +00:00
return $this->getKey();
}
/**
* Get the password for the user.
*
* @return string
*/
2016-03-05 00:18:10 +00:00
public function getAuthPassword()
{
2016-02-29 15:59:36 +00:00
return $this->password;
}
/**
* Get the e-mail address where password reminders are sent.
*
* @return string
*/
2016-03-05 00:18:10 +00:00
public function getReminderEmail()
{
2016-02-29 15:59:36 +00:00
return $this->email;
}
2016-03-14 16:37:38 +00:00
/**
* Get the remember token for the user.
*
* @return \Illuminate\Support\Collection|mixed|static
*/
2016-03-05 00:18:10 +00:00
public function getRememberToken()
{
2016-02-29 15:59:36 +00:00
return $this->remember_token;
}
2016-03-14 16:37:38 +00:00
/**
* Set the remember token for the user.
*
* @param string $value
*/
2016-03-05 00:18:10 +00:00
public function setRememberToken($value)
{
2016-02-29 15:59:36 +00:00
$this->remember_token = $value;
}
2016-03-14 16:37:38 +00:00
/**
* Get the name of the remember token for the user.
*
* @return string
*/
2016-03-05 00:18:10 +00:00
public function getRememberTokenName()
{
2016-02-29 15:59:36 +00:00
return 'remember_token';
}
2016-03-05 00:18:10 +00:00
/**
* Get the full name of the user.
*
* @return string
*/
public function getFullNameAttribute()
{
return $this->first_name.' '.$this->last_name;
}
2016-03-14 16:37:38 +00:00
/**
* Boot all of the bootable traits on the model.
*/
2016-03-05 00:18:10 +00:00
public static function boot()
{
2016-02-29 15:59:36 +00:00
parent::boot();
2016-03-05 00:18:10 +00:00
static::creating(function ($user) {
2016-02-29 15:59:36 +00:00
$user->confirmation_code = str_random();
$user->api_key = str_random(60);
2016-02-29 15:59:36 +00:00
});
}
}