From a514ba3adc76cb37ab6211640967aa164d56a9c5 Mon Sep 17 00:00:00 2001 From: Igor Scheller Date: Sun, 3 Nov 2019 00:25:35 +0100 Subject: [PATCH] HasUserModel: Moved user method to trait --- src/Models/User/HasUserModel.php | 18 ++----------- src/Models/User/UsesUserModel.php | 25 +++++++++++++++++++ .../User/Stub/HasUserModelImplementation.php | 9 ------- ...serModelTest.php => UsesUserModelTest.php} | 15 ++++++----- 4 files changed, 36 insertions(+), 31 deletions(-) create mode 100644 src/Models/User/UsesUserModel.php delete mode 100644 tests/Unit/Models/User/Stub/HasUserModelImplementation.php rename tests/Unit/Models/User/{HasUserModelTest.php => UsesUserModelTest.php} (60%) diff --git a/src/Models/User/HasUserModel.php b/src/Models/User/HasUserModel.php index 6d1323de..2b7fdda9 100644 --- a/src/Models/User/HasUserModel.php +++ b/src/Models/User/HasUserModel.php @@ -3,17 +3,11 @@ namespace Engelsystem\Models\User; use Engelsystem\Models\BaseModel; -use Illuminate\Database\Eloquent\Relations\BelongsTo; -/** - * @property integer $user_id - * - * @property-read \Illuminate\Database\Query\Builder|\Engelsystem\Models\User\User $user - * - * @method static \Illuminate\Database\Query\Builder|static whereUserId($value) - */ abstract class HasUserModel extends BaseModel { + use UsesUserModel; + /** @var string The primary key for the model */ protected $primaryKey = 'user_id'; @@ -24,12 +18,4 @@ abstract class HasUserModel extends BaseModel /** The relationships that should be touched on save */ protected $touches = ['user']; - - /** - * @return BelongsTo - */ - public function user() - { - return $this->belongsTo(User::class); - } } diff --git a/src/Models/User/UsesUserModel.php b/src/Models/User/UsesUserModel.php new file mode 100644 index 00000000..84795480 --- /dev/null +++ b/src/Models/User/UsesUserModel.php @@ -0,0 +1,25 @@ +belongsTo(User::class); + } +} diff --git a/tests/Unit/Models/User/Stub/HasUserModelImplementation.php b/tests/Unit/Models/User/Stub/HasUserModelImplementation.php deleted file mode 100644 index 6d442bdd..00000000 --- a/tests/Unit/Models/User/Stub/HasUserModelImplementation.php +++ /dev/null @@ -1,9 +0,0 @@ -assertInstanceOf(BelongsTo::class, $model->user()); }