Miguel N
8942623bde
This commit moves most controller logic onto Services. Services are part of the Service-Repository pattern. The models act as repositories. Services are easily testable and are needed for the upcoming API, in order to avoid duplicated code and to maintain a single source of "truth". The User, Vacancy and Vote controllers still need their logic moved onto services.
28 lines
498 B
PHP
28 lines
498 B
PHP
<?php
|
|
|
|
|
|
namespace App\Services;
|
|
|
|
|
|
use App\Application;
|
|
use App\Comment;
|
|
use Illuminate\Support\Facades\Auth;
|
|
|
|
class CommentService
|
|
{
|
|
|
|
public function addComment(Application $application, $comment): Comment {
|
|
return Comment::create([
|
|
'authorID' => Auth::user()->id,
|
|
'applicationID' => $application->id,
|
|
'text' => $comment,
|
|
]);
|
|
}
|
|
|
|
public function deleteComment(Comment $comment): ?bool
|
|
{
|
|
return $comment->delete();
|
|
}
|
|
|
|
}
|