2022-01-30

JSON data type in entity class in php [duplicate]

I am using symfony/doctrine orm in my php and database is mysql. As of now I am creating manual table in mysql by using below command.

create table FileUpload (id int , countryCode varchar(30),fileData json);

I want Doctrine to create this table and datatype of filedata should be json. As of now in my entity class I am taking datatype as string. what datatype I should take in entity class so that in DB data with JSON datatype should be created?

What modification I need to do in below my existing class?

FileUpload.php

<?php

namespace App\Entity;

use ApiPlatform\Core\Annotation\ApiResource;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;

/** 
 * @ORM\Entity 
 * @ORM\Table(name="FileUpload") 
 */
class FileUpload
{
    /**
     * @ORM\Column(type="string")
     * @ORM\Id
     */
    private $countryCode;

    /** 
     * @ORM\Column(type = "string") 
     */
    private $fileData;



    public function __construct(
        string $countryCode,
        string $fileData
    ) {
        $this->countryCode = $countryCode;
        $this->fileData = $fileData;
    }


    /** 
     * Set countryCode 
     * 
     * @param string $countryCode 
     * 
     * @return FileUpload 
     */

    public function setCountryCode($countryCode)
    {
        $this->countryCode = $countryCode;
        return $this;
    }

    /** 
     * Get countryCode 
     * 
     * @return string 
     */

    public function getCountryCode()
    {
        return $this->countryCode;
    }

    /**
     * Set fileData 
     * 
     * @param string $fileData
     * 
     * @return FileUpload 
     */

    public function setFileData($fileData)
    {
        $this->fileData = $fileData;
        return $this;
    }

    /** 
     * Get fileData 
     * 
     * @return string 
     */

    public function getFileData()
    {
        return $this->fileData;
    }
}


from Recent Questions - Stack Overflow https://ift.tt/HTMbfvEiG
https://bit.ly/3GblJNq

No comments:

Post a Comment