'Couldn't find constant subresourceOperations, class App\Entity\Comment
i have two table comment and author between them OneToMany relation, i want to display author of comment but it gives me error [Semantical Error] Couldn't find constant subresourceOperations, class App\Entity\Comment
.
src\Entity\Comment.php
<?php
namespace App\Entity;
use ApiPlatform\Core\Annotation\ApiResource;
use App\Repository\CommentRepository;
use Symfony\Component\Serializer\Annotation\Groups;
use Doctrine\ORM\Mapping as ORM;
/**
* @ApiResource(itemOperations={"GET","DELETE",
* "PUT"={
* "access_control"="is_granted('IS_AUTHENTICATED_FULLY') and object.getAuthor() == user"
* }
* },
* collectionOperations={"GET",
* "POST"={
* "access_control"="is_granted('IS_AUTHENTICATED_FULLY')"
* },
* subresourceOperations={
* "api_posts_comments_get_subresource"={
* "normalization_context"={
* "groups"={"get-comment-with-author"}
* }
* }
* }
* }
*)
* @ORM\Entity(repositoryClass=CommentRepository::class)
*/
Solution 1:[1]
as @julien B said, you have to close "collectionOperations" bracket "}" and put itemOperations and collectionOperations and subresourceOperations at the same level
namespace App\Entity;
use ApiPlatform\Core\Annotation\ApiResource;
use App\Repository\CommentRepository;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\Groups;
/**
* @ApiResource(
* itemOperations={"GET", "DELETE",
* "PUT"={
* "access_control"="is_granted('IS_AUTHENTICATED_FULLY') and object.getAuthor() == user"
* }
* },
* collectionOperations={
* "GET",
* "POST"={
* "access_control"="is_granted('IS_AUTHENTICATED_FULLY')"
* }
* },
* subresourceOperations={
* "api_posts_comments_get_subresource"={
* "normalization_context"={
* "groups"={"get-comment-with-author"}
* }
* }
* }
* )
* @ORM\Entity(repositoryClass=CommentRepository::class)
*/
class Comment
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Mohamed CHIBANI |