Add a column for the user avatar #226

This commit is contained in:
Nabeel Shahzad 2018-04-02 06:47:31 -05:00
parent bb73af3806
commit f84ff8de92
2 changed files with 17 additions and 2 deletions

View File

@ -28,6 +28,7 @@ class CreateUsersTable extends Migration
$table->unsignedBigInteger('flights')->default(0); $table->unsignedBigInteger('flights')->default(0);
$table->unsignedBigInteger('flight_time')->nullable()->default(0); $table->unsignedBigInteger('flight_time')->nullable()->default(0);
$table->unsignedBigInteger('transfer_time')->nullable()->default(0); $table->unsignedBigInteger('transfer_time')->nullable()->default(0);
$table->string('avatar')->nullable();
$table->string('timezone', 64)->nullable(); $table->string('timezone', 64)->nullable();
$table->unsignedTinyInteger('status')->nullable()->default(0); $table->unsignedTinyInteger('status')->nullable()->default(0);
$table->unsignedTinyInteger('state')->nullable()->default(0); $table->unsignedTinyInteger('state')->nullable()->default(0);

View File

@ -15,7 +15,7 @@ use Laratrust\Traits\LaratrustUserTrait;
* @property string $email * @property string $email
* @property string $password * @property string $password
* @property string $api_key * @property string $api_key
* @property string current_airport_id * @property string curr_airport_id
* @property string home_airport_id * @property string home_airport_id
* @property Flight[] $flights * @property Flight[] $flights
* @property string $flight_time * @property string $flight_time
@ -56,7 +56,7 @@ class User extends Authenticatable
'flights', 'flights',
'flight_time', 'flight_time',
'transferred_time', 'transferred_time',
'balance', 'avatar',
'timezone', 'timezone',
'state', 'state',
'status', 'status',
@ -123,6 +123,20 @@ class User extends Authenticatable
$this->attributes['timezone'] = $value; $this->attributes['timezone'] = $value;
} }
/**
* Return a File model
*/
public function getAvatarAttribute()
{
if (!$this->attributes['avatar']) {
return null;
}
return new File([
'path' => $this->attributes['avatar']
]);
}
/** /**
* @param mixed $size Size of the gravatar, in pixels * @param mixed $size Size of the gravatar, in pixels
* @return string * @return string