I needd to return a JsonResponse inside persist fuction.
this is an example of my DataPersister class, the goal it's return a JsonResponse, when i try, i get the error: The controller must return a \"Symfony\Component\HttpFoundation\Response\" object but it returned an object of type App\Entity\VerificationCodes.
<?php
// api/src/DataPersister/UsersDataPersister.php
namespace App\DataPersister;
use ApiPlatform\Core\DataPersister\DataPersisterInterface;
use App\Entity\Users;
use Doctrine\Common\Persistence\ManagerRegistry;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\JsonResponse;
final class UsersDataPersister implements DataPersisterInterface
{
private $managerRegistry;
public function __construct(ManagerRegistry $managerRegistry)
{
$this->managerRegistry = $managerRegistry;
}
public function supports($data): bool
{
return $data instanceof Users;
}
public function persist($data){
$em = $this->managerRegistry->getManagerForClass(Users::class);
$user = new Users();
//Persist User with encode password
return $user;
return new JsonResponse(['response'=>'yes']);
}
public function remove($data)
{
throw new \RuntimeException('"remove" is not supported');
}
}
please help me or tell me what i can do, than you