From e44b8611fadce7b7f24ebf83c62e515bd88d6df3 Mon Sep 17 00:00:00 2001 From: Jay Sizzla Date: Wed, 6 Nov 2024 08:51:42 +0000 Subject: [PATCH] Add Migration & Models --- app/Models/User.php | 12 +++++ app/Models/UserBlock.php | 48 +++++++++++++++++++ ..._11_06_083742_create_block_user_system.php | 41 ++++++++++++++++ 3 files changed, 101 insertions(+) create mode 100644 app/Models/UserBlock.php create mode 100644 database/migrations/2024_11_06_083742_create_block_user_system.php diff --git a/app/Models/User.php b/app/Models/User.php index 3d3c24c0c2..b1b0ad8e4c 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -199,6 +199,18 @@ public function chatStatus(): \Illuminate\Database\Eloquent\Relations\BelongsTo return $this->belongsTo(ChatStatus::class, 'chat_status_id', 'id'); } + /** + * Belongs to many Blocked Users. + * + * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany + */ + public function blockedUsers(): \Illuminate\Database\Eloquent\Relations\BelongsToMany + { + return $this->belongsToMany(BlockedUsers::class, 'user_id', 'blocked_user_id') + ->as('blocked') + ->withTimestamps(); + } + /** * Belongs To Many Bookmarks. * diff --git a/app/Models/UserBlock.php b/app/Models/UserBlock.php new file mode 100644 index 0000000000..f25dd9645c --- /dev/null +++ b/app/Models/UserBlock.php @@ -0,0 +1,48 @@ + + * @license https://www.gnu.org/licenses/agpl-3.0.en.html/ GNU Affero General Public License v3.0 + */ + +namespace App\Models; + +use App\Traits\Auditable; +use Illuminate\Database\Eloquent\Factories\HasFactory; +use Illuminate\Database\Eloquent\Model; + +/** + * App\Models\UserAudible. + * + * @property int $id + * @property int $user_id + * @property int $blocked_user_id + * @property \Illuminate\Support\Carbon|null $created_at + * @property \Illuminate\Support\Carbon|null $updated_at + */ +class UserAudible extends Model +{ + use Auditable; + + /** @use HasFactory<\Database\Factories\BookmarkFactory> */ + use HasFactory; + + /** + * Belongs To A User. + * + * @return \Illuminate\Database\Eloquent\Relations\BelongsTo + */ + public function user(): \Illuminate\Database\Eloquent\Relations\BelongsTo + { + return $this->belongsTo(User::class)->withTrashed(); + } +} diff --git a/database/migrations/2024_11_06_083742_create_block_user_system.php b/database/migrations/2024_11_06_083742_create_block_user_system.php new file mode 100644 index 0000000000..f30a1b0b90 --- /dev/null +++ b/database/migrations/2024_11_06_083742_create_block_user_system.php @@ -0,0 +1,41 @@ + + * @license https://www.gnu.org/licenses/agpl-3.0.en.html/ GNU Affero General Public License v3.0 + */ + +use Illuminate\Database\Migrations\Migration; +use Illuminate\Database\Schema\Blueprint; +use Illuminate\Support\Facades\Schema; + +return new class () extends Migration { + /** + * Run the migrations. + */ + public function up(): void + { + Schema::create('user_blocks', function (Blueprint $table): void { + $table->unsignedInteger('user_id'); + $table->unsignedInteger('blocked_user_id'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('user_blocks'); + } +};