From f84ff8de92b71ddeb0bf0abb35e323c8bc7b3798 Mon Sep 17 00:00:00 2001 From: Nabeel Shahzad Date: Mon, 2 Apr 2018 06:47:31 -0500 Subject: [PATCH] Add a column for the user avatar #226 --- .../2017_06_08_0000_create_users_table.php | 1 + app/Models/User.php | 18 ++++++++++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/app/Database/migrations/2017_06_08_0000_create_users_table.php b/app/Database/migrations/2017_06_08_0000_create_users_table.php index 228c2e44..14056ef7 100755 --- a/app/Database/migrations/2017_06_08_0000_create_users_table.php +++ b/app/Database/migrations/2017_06_08_0000_create_users_table.php @@ -28,6 +28,7 @@ class CreateUsersTable extends Migration $table->unsignedBigInteger('flights')->default(0); $table->unsignedBigInteger('flight_time')->nullable()->default(0); $table->unsignedBigInteger('transfer_time')->nullable()->default(0); + $table->string('avatar')->nullable(); $table->string('timezone', 64)->nullable(); $table->unsignedTinyInteger('status')->nullable()->default(0); $table->unsignedTinyInteger('state')->nullable()->default(0); diff --git a/app/Models/User.php b/app/Models/User.php index 78ab6f7b..8d6fbcf8 100755 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -15,7 +15,7 @@ use Laratrust\Traits\LaratrustUserTrait; * @property string $email * @property string $password * @property string $api_key - * @property string current_airport_id + * @property string curr_airport_id * @property string home_airport_id * @property Flight[] $flights * @property string $flight_time @@ -56,7 +56,7 @@ class User extends Authenticatable 'flights', 'flight_time', 'transferred_time', - 'balance', + 'avatar', 'timezone', 'state', 'status', @@ -123,6 +123,20 @@ class User extends Authenticatable $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 * @return string