Initial project

This commit is contained in:
2026-05-01 00:41:02 +03:30
parent d324115341
commit cde71d5761
172 changed files with 22074 additions and 12 deletions

View File

@@ -0,0 +1,81 @@
<?php
namespace App\Policies;
use App\Models\Conversation;
use App\Models\ConversationParticipant;
use App\Models\User;
class ConversationPolicy
{
/**
* Determine whether the user can view any models.
*/
public function viewAny(User $user): bool
{
return true;
}
/**
* Determine whether the user can view the model.
*/
public function view(User $user, Conversation $conversation): bool
{
return $this->participates($user, $conversation);
}
/**
* Determine whether the user can create models.
*/
public function create(User $user): bool
{
return true;
}
/**
* Determine whether the user can update the model.
*/
public function update(User $user, Conversation $conversation): bool
{
return $conversation->participants()
->where('user_id', $user->id)
->where('role', ConversationParticipant::RoleAdmin)
->exists();
}
/**
* Determine whether the user can delete the model.
*/
public function delete(User $user, Conversation $conversation): bool
{
return $conversation->created_by_id === $user->id;
}
/**
* Determine whether the user can restore the model.
*/
public function restore(User $user, Conversation $conversation): bool
{
return false;
}
/**
* Determine whether the user can permanently delete the model.
*/
public function forceDelete(User $user, Conversation $conversation): bool
{
return false;
}
public function sendMessage(User $user, Conversation $conversation): bool
{
return $this->participates($user, $conversation);
}
private function participates(User $user, Conversation $conversation): bool
{
return $conversation->participants()
->where('user_id', $user->id)
->exists();
}
}