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

(Add) Block users system #4341

Draft
wants to merge 1 commit into
base: 8.x.x
Choose a base branch
from
Draft
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
12 changes: 12 additions & 0 deletions app/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,18 @@
return $this->belongsTo(ChatStatus::class, 'chat_status_id', 'id');
}

/**
* Belongs to many Blocked Users.
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany<User, $this>
*/
public function blockedUsers(): \Illuminate\Database\Eloquent\Relations\BelongsToMany
{
return $this->belongsToMany(BlockedUsers::class, 'user_id', 'blocked_user_id')

Check failure on line 209 in app/Models/User.php

View workflow job for this annotation

GitHub Actions / php 8.3 on ubuntu-22.04

Class App\Models\BlockedUsers not found.

Check failure on line 209 in app/Models/User.php

View workflow job for this annotation

GitHub Actions / php 8.3 on ubuntu-22.04

Method App\Models\User::blockedUsers() should return Illuminate\Database\Eloquent\Relations\BelongsToMany<App\Models\User, $this(App\Models\User)> but returns Illuminate\Database\Eloquent\Relations\BelongsToMany<App\Models\BlockedUsers, $this(App\Models\User)>.

Check failure on line 209 in app/Models/User.php

View workflow job for this annotation

GitHub Actions / php 8.3 on ubuntu-22.04

Parameter #1 $related of method Illuminate\Database\Eloquent\Model::belongsToMany() expects class-string<Illuminate\Database\Eloquent\Model>, string given.

Check failure on line 209 in app/Models/User.php

View workflow job for this annotation

GitHub Actions / php 8.3 on ubuntu-22.04

Unable to resolve the template type TRelatedModel in call to method Illuminate\Database\Eloquent\Model::belongsToMany()
->as('blocked')
->withTimestamps();
}

/**
* Belongs To Many Bookmarks.
*
Expand Down
48 changes: 48 additions & 0 deletions app/Models/UserBlock.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

declare(strict_types=1);

/**
* NOTICE OF LICENSE.
*
* UNIT3D Community Edition is open-sourced software licensed under the GNU Affero General Public License v3.0
* The details is bundled with this project in the file LICENSE.txt.
*
* @project UNIT3D Community Edition
*
* @author HDVinnie <[email protected]>
* @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<User, $this>
*/
public function user(): \Illuminate\Database\Eloquent\Relations\BelongsTo
{
return $this->belongsTo(User::class)->withTrashed();
}
}
41 changes: 41 additions & 0 deletions database/migrations/2024_11_06_083742_create_block_user_system.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

declare(strict_types=1);

/**
* NOTICE OF LICENSE.
*
* UNIT3D Community Edition is open-sourced software licensed under the GNU Affero General Public License v3.0
* The details is bundled with this project in the file LICENSE.txt.
*
* @project UNIT3D Community Edition
*
* @author Roardom <[email protected]>
* @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');
}
};
Loading