Выдержка
class PostFormViewModel
{
public function __construct(User $user, Post $post = null)
{
$this->user = $user;
$this->post = $post;
}
public function post(): Post
{
return $this->post ?? new Post();
}
public function categories(): Collection
{
return Category::allowedForUser($this->user)->get();
}
}