feat: add reciprocal user blocking
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace App\Actions;
|
||||
|
||||
use App\Models\User;
|
||||
use App\Models\UserBlock;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class BlockUser
|
||||
{
|
||||
public function execute(User $blocker, User $blocked): UserBlock
|
||||
{
|
||||
return DB::transaction(function () use ($blocker, $blocked): UserBlock {
|
||||
$userBlock = UserBlock::query()->firstOrCreate([
|
||||
'blocker_id' => $blocker->getKey(),
|
||||
'blocked_id' => $blocked->getKey(),
|
||||
]);
|
||||
|
||||
$blocker->following()->detach($blocked->getKey());
|
||||
$blocker->followers()->detach($blocked->getKey());
|
||||
|
||||
return $userBlock;
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user