26 lines
648 B
PHP
26 lines
648 B
PHP
<?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;
|
|
});
|
|
}
|
|
}
|