Synchro back-office, fix on tariffs

This commit is contained in:
Ludovic CANDELLIER
2021-10-26 21:41:46 +02:00
parent c150be2c3e
commit 86f6ee9a13
45 changed files with 1095 additions and 406 deletions

11
app/Traits/CanComment.php Normal file
View File

@@ -0,0 +1,11 @@
<?php
namespace App\Traits;
trait CanComment
{
public function needsCommentApproval($model): bool
{
return true;
}
}

View File

@@ -0,0 +1,36 @@
<?php
namespace App\Traits;
use Illuminate\Database\Eloquent\Model;
use App\Contracts\Commentator;
use Illuminate\Database\Eloquent\Relations\MorphMany;
use App\Models\Core\Comment;
trait HasComments
{
public function comments()
{
return $this->morphMany(Comment::class, 'commentable');
}
public function comment(string $comment)
{
return $this->commentAsUser(auth()->user(), $comment);
}
public function commentAsUser(?Model $user, string $comment)
{
$comment = new Comment([
'comment' => $comment,
'is_approved' => ($user instanceof Commentator) ? ! $user->needsCommentApproval($this) : false,
'user_id' => is_null($user) ? null : $user->getKey(),
'commentable_id' => $this->getKey(),
'commentable_type' => get_class(),
]);
return $this->comments()->save($comment);
}
}