/**
  * Run the migrations.
  *
  * @return void
  */
 public function up()
 {
     Schema::table(\App\Models\Article::getTableName(), function (Blueprint $table) {
         $table->foreign('permalink')->references('permalink')->on(\App\Models\ArticlePermalink::getTableName());
     });
 }
 /**
  * Reverse the migrations.
  *
  * @return void
  */
 public function down()
 {
     DB::statement(sprintf('DROP TABLE %s CASCADE', \App\Models\ArticlePermalink::getTableName()));
 }
Пример #3
0
 public function testGetPermalinks()
 {
     $entity = factory(Article::class)->create();
     $this->addPermalinksToArticles([$entity]);
     $entity->push();
     $count = ArticlePermalink::where('article_id', '=', $entity->article_id)->count();
     $this->get('/articles/' . $entity->article_id . '/permalinks');
     $this->assertResponseOk();
     $this->shouldReturnJson();
     $object = json_decode($this->response->getContent());
     $this->assertEquals(count($object), $count);
 }
Пример #4
0
 /**
  * @param string $id article_id or permalink
  * @return Article
  * @throws ModelNotFoundException
  */
 public function findByIdentifier($id)
 {
     //if the id is a uuid, try that or fail.
     if (Uuid::isValid($id)) {
         return parent::findOrFail($id);
     }
     //otherwise attempt treat the id as a permalink and first try the model, then try the history
     try {
         return $this->where('permalink', '=', $id)->firstOrFail();
     } catch (ModelNotFoundException $e) {
         //id or permalink not found, try permalink history
         return ArticlePermalink::findOrFail($id)->article;
     }
 }