Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added is_flying Attribute to User Model #1729

Open
wants to merge 7 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion app/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Models;

use App\Models\Enums\JournalType;
use App\Models\Enums\PirepState;
use App\Models\Traits\JournalTrait;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Database\Eloquent\Casts\Attribute;
Expand All @@ -27,6 +28,7 @@
* @property string callsign
* @property string name
* @property string name_private Only first name, rest are initials
* @property bool is_flying
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should go in the bottom of the list where the properties are

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And to in_flight

* @property string email
* @property string password
* @property string api_key
Expand Down Expand Up @@ -66,7 +68,6 @@
* @property Airport location
* @property Bid[] bids
*
* @mixin \Illuminate\Database\Eloquent\Builder
* @mixin \Illuminate\Notifications\Notifiable
* @mixin \Laratrust\Traits\HasRolesAndPermissions
*/
Expand Down Expand Up @@ -216,6 +217,20 @@ public function atc(): Attribute
);
}

/**
* Returns a boolean value whether the pilot is actively flying or not.
*
* @return Attribute
*/
public function isFlying(): Attribute
{
return Attribute::make(
get: function ($_, $attrs) {
return (bool) Pirep::where(['user_id' => $this->id, 'state' => PirepState::IN_PROGRESS])->count();
Copy link
Owner

@nabeelio nabeelio Dec 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would change this to use latest('updated_at'). In case there is a bugged/old PIREP.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe the name also to inFlight(). Since you're checking if they're in a particular state. Then the same property can probably be added to Aircraft later.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can also, instead of count(), use exists(). Then you don't need to cast it. And you can add more constraints, to say in the last day, etc. But I think latest on when it's been modified should be ok. There will be ongoing updates to that record.

}
);
}

/**
* Return a "privatized" version of someones name - First and middle names full, last name initials
*
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@
"nikolaposa/version": "^4.2",
"spatie/laravel-activitylog": "^4.7",
"socialiteproviders/vatsim": "^5.0",
"socialiteproviders/ivao": "^4.0"
"socialiteproviders/ivao": "^4.0",
"mailersend/laravel-driver": "^2.6"
},
"require-dev": {
"barryvdh/laravel-debugbar": "^3.8.1",
Expand Down
4 changes: 4 additions & 0 deletions config/mail.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@
'path' => '/usr/sbin/sendmail -bs',
],

'mailersend' => [
'transport' => 'mailersend',
],

'log' => [
'transport' => 'log',
'channel' => env('MAIL_LOG_CHANNEL', 'stack'),
Expand Down
Loading