2016-09-24 7 views
-1

현재 Symfony 환경에서 Laravel 프레임 워크에 익숙해 지려고합니다. 지금은 모든 것이 꽤 괜찮아 보입니다. 그러나 Laravel에서 누락 된 것이 하나 있습니다. 그렇지 않으면 그 방법을 찾지 못했습니다.Laravel의 엔티티 기반 스키마 업데이트

// src/AppBundle/Entity/Product.php 
namespace AppBundle\Entity; 

use Doctrine\ORM\Mapping as ORM; 

/** 
* @ORM\Entity 
* @ORM\Table(name="product") 
*/ 
class Product 
{ 
    /** 
    * @ORM\Column(type="integer") 
    * @ORM\Id 
    * @ORM\GeneratedValue(strategy="AUTO") 
    */ 
    private $id; 

    /** 
    * @ORM\Column(type="string", length=100) 
    */ 
    private $name; 

    /** 
    * @ORM\Column(type="decimal", scale=2) 
    */ 
    private $price; 

    /** 
    * @ORM\Column(type="text") 
    */ 
    private $description; 
} 

이 파일을 생성 한 후, 하나는 단순히 예를 들어 MySQL 데이터베이스를 업데이트 php app/console schema:doctrine:update --force을 실행할 수 있습니다 : 심포니에서

, 하나는 다음과 같이 엔티티를 생성 할 수있는 옵션이 있습니다.

이제 Laravel이 Eloquent, 모델 및 마이그레이션을 사용하여 데이터베이스를 적절하게 업데이트한다는 사실을 읽었습니다. 그러나 Symfony에서 사용 된 방법으로 데이터베이스를 업데이트하는 것과 비슷한 방법이 있는지 궁금합니다. 따라서 명령을 실행하면 생성 한 엔티티를 기반으로 데이터베이스가 자동으로 업데이트됩니다.

전혀 가능합니까?

답변

1

당신이 원하는 것은 네이티브로 존재하지 않습니다.

그러나 찾고있는 멋진 패키지는 annotation mapping입니다. 물론, 이것은 그것보다 훨씬 더 중요하며, 실제로 당신에게 중요한 모든 결핍 조각들을 거의 제공합니다. 답에 대한

<?php 

use Doctrine\ORM\Mapping AS ORM; 

/** 
* @ORM\Entity 
* @ORM\Table(name="articles") 
*/ 
class Article 
{ 
    /** 
    * @ORM\Id 
    * @ORM\GeneratedValue 
    * @ORM\Column(type="integer") 
    */ 
    protected $id; 

    /** 
    * @ORM\Column(type="string") 
    */ 
    protected $title; 

    public function getId() 
    { 
     return $this->id; 
    } 

    public function getTitle() 
    { 
     return $this->title; 
    } 

    public function setTitle($title) 
    { 
     $this->title = $title; 
    } 
}  
+0

감사 :

You can find the package here

You can find the documentation here

여기 Laravel의 교리에서 메타 매핑을 사용하는 예제입니다! 이것은 제가 찾고있는 것입니다. 그에 따라 Laravel이 데이터베이스를 업데이트하는 특별한 명령이 있습니까? – Stan