Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F117920840
D3502.1775428617.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Authored By
Unknown
Size
7 KB
Referenced Files
None
Subscribers
None
D3502.1775428617.diff
View Options
diff --git a/src/app/Fs/Item.php b/src/app/Fs/Item.php
--- a/src/app/Fs/Item.php
+++ b/src/app/Fs/Item.php
@@ -3,6 +3,7 @@
namespace App\Fs;
use App\User;
+use App\Traits\BelongsToUserTrait;
use App\Traits\UuidStrKeyTrait;
use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\Model;
@@ -18,6 +19,7 @@
*/
class Item extends Model
{
+ use BelongsToUserTrait;
use SoftDeletes;
use UuidStrKeyTrait;
@@ -165,14 +167,4 @@
);
}
}
-
- /**
- * The user to which this item belongs.
- *
- * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
- */
- public function user()
- {
- return $this->belongsTo(User::class, 'user_id', 'id');
- }
}
diff --git a/src/app/Mail/PasswordReset.php b/src/app/Mail/PasswordReset.php
--- a/src/app/Mail/PasswordReset.php
+++ b/src/app/Mail/PasswordReset.php
@@ -75,6 +75,7 @@
'short_code' => VerificationCode::generateShortCode(),
]);
+ // @phpstan-ignore-next-line
$code->user = new User([
'email' => 'test@' . \config('app.domain'),
]);
diff --git a/src/app/Policy/RateLimit.php b/src/app/Policy/RateLimit.php
--- a/src/app/Policy/RateLimit.php
+++ b/src/app/Policy/RateLimit.php
@@ -2,10 +2,13 @@
namespace App\Policy;
+use App\Traits\BelongsToUserTrait;
use Illuminate\Database\Eloquent\Model;
class RateLimit extends Model
{
+ use BelongsToUserTrait;
+
protected $fillable = [
'user_id',
'owner_id',
@@ -17,11 +20,6 @@
public function owner()
{
- $this->belongsTo('App\User');
- }
-
- public function user()
- {
- $this->belongsTo('App\User');
+ $this->belongsTo(\App\User::class);
}
}
diff --git a/src/app/SignupInvitation.php b/src/app/SignupInvitation.php
--- a/src/app/SignupInvitation.php
+++ b/src/app/SignupInvitation.php
@@ -5,20 +5,21 @@
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Model;
use App\Traits\BelongsToTenantTrait;
+use App\Traits\BelongsToUserTrait;
use App\Traits\UuidStrKeyTrait;
/**
* The eloquent definition of a signup invitation.
*
- * @property string $email
- * @property string $id
- * @property ?int $tenant_id
- * @property ?\App\Tenant $tenant
- * @property ?\App\User $user
+ * @property string $email
+ * @property string $id
+ * @property ?int $tenant_id
+ * @property ?int $user_id
*/
class SignupInvitation extends Model
{
use BelongsToTenantTrait;
+ use BelongsToUserTrait;
use UuidStrKeyTrait;
// just created
@@ -74,14 +75,4 @@
{
return ($this->status & self::STATUS_SENT) > 0;
}
-
- /**
- * The account to which the invitation was used for.
- *
- * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
- */
- public function user()
- {
- return $this->belongsTo(User::class, 'user_id', 'id');
- }
}
diff --git a/src/app/Traits/BelongsToUserTrait.php b/src/app/Traits/BelongsToUserTrait.php
new file mode 100644
--- /dev/null
+++ b/src/app/Traits/BelongsToUserTrait.php
@@ -0,0 +1,16 @@
+<?php
+
+namespace App\Traits;
+
+trait BelongsToUserTrait
+{
+ /**
+ * The user to which this object belongs.
+ *
+ * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
+ */
+ public function user()
+ {
+ return $this->belongsTo(\App\User::class);
+ }
+}
diff --git a/src/app/UserAlias.php b/src/app/UserAlias.php
--- a/src/app/UserAlias.php
+++ b/src/app/UserAlias.php
@@ -2,6 +2,7 @@
namespace App;
+use App\Traits\BelongsToUserTrait;
use Illuminate\Database\Eloquent\Model;
/**
@@ -13,6 +14,8 @@
*/
class UserAlias extends Model
{
+ use BelongsToUserTrait;
+
/** @var array<int, string> The attributes that are mass assignable */
protected $fillable = ['user_id', 'alias'];
@@ -25,14 +28,4 @@
{
$this->attributes['alias'] = \strtolower($alias);
}
-
- /**
- * The user to which this alias belongs.
- *
- * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
- */
- public function user()
- {
- return $this->belongsTo(User::class, 'user_id', 'id');
- }
}
diff --git a/src/app/UserPassword.php b/src/app/UserPassword.php
--- a/src/app/UserPassword.php
+++ b/src/app/UserPassword.php
@@ -2,6 +2,7 @@
namespace App;
+use App\Traits\BelongsToUserTrait;
use Illuminate\Database\Eloquent\Model;
/**
@@ -13,6 +14,8 @@
*/
class UserPassword extends Model
{
+ use BelongsToUserTrait;
+
/** @var bool Indicates if the model should be timestamped. */
public $timestamps = false;
@@ -26,14 +29,4 @@
/** @var array<int, string> The attributes that should be hidden for arrays. */
protected $hidden = ['password'];
-
- /**
- * The user to which this entry belongs.
- *
- * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
- */
- public function user()
- {
- return $this->belongsTo(User::class, 'user_id', 'id');
- }
}
diff --git a/src/app/UserSetting.php b/src/app/UserSetting.php
--- a/src/app/UserSetting.php
+++ b/src/app/UserSetting.php
@@ -2,6 +2,7 @@
namespace App;
+use App\Traits\BelongsToUserTrait;
use Illuminate\Database\Eloquent\Model;
/**
@@ -14,16 +15,8 @@
*/
class UserSetting extends Model
{
+ use BelongsToUserTrait;
+
/** @var array<int, string> The attributes that are mass assignable */
protected $fillable = ['user_id', 'key', 'value'];
-
- /**
- * The user to which this setting belongs.
- *
- * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
- */
- public function user()
- {
- return $this->belongsTo(User::class, 'user_id', 'id');
- }
}
diff --git a/src/app/VerificationCode.php b/src/app/VerificationCode.php
--- a/src/app/VerificationCode.php
+++ b/src/app/VerificationCode.php
@@ -2,6 +2,7 @@
namespace App;
+use App\Traits\BelongsToUserTrait;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Model;
@@ -12,12 +13,13 @@
* @property string $code The code
* @property \Carbon\Carbon $expires_at Expiration date-time
* @property string $mode Mode, e.g. password-reset
- * @property \App\User $user User object
* @property int $user_id User identifier
* @property string $short_code Short code
*/
class VerificationCode extends Model
{
+ use BelongsToUserTrait;
+
// Code expires after so many hours
public const SHORTCODE_LENGTH = 8;
@@ -70,14 +72,4 @@
// @phpstan-ignore-next-line
return $this->expires_at ? Carbon::now()->gte($this->expires_at) : false;
}
-
- /**
- * The user to which this code belongs.
- *
- * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
- */
- public function user()
- {
- return $this->belongsTo(User::class, 'user_id', 'id');
- }
}
diff --git a/src/tests/Unit/Mail/PasswordResetTest.php b/src/tests/Unit/Mail/PasswordResetTest.php
--- a/src/tests/Unit/Mail/PasswordResetTest.php
+++ b/src/tests/Unit/Mail/PasswordResetTest.php
@@ -22,6 +22,7 @@
'short_code' => 'short-code',
]);
+ // @phpstan-ignore-next-line
$code->user = new User([
'name' => 'User Name',
]);
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, Apr 5, 10:36 PM (23 h, 26 m ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
18820786
Default Alt Text
D3502.1775428617.diff (7 KB)
Attached To
Mode
D3502: BelongsToUser Trait
Attached
Detach File
Event Timeline