/**
  * Test
  *
  * @test
  */
 public function testCustomUniqueQueryScope()
 {
     $authorBob = Author::create(['name' => 'Bob']);
     $authorPam = Author::create(['name' => 'Pam']);
     // Bob's first post
     $post = new PostWithUniqueSlugConstraints(['title' => 'My first post']);
     $post->author()->associate($authorBob);
     $post->save();
     $this->assertEquals('my-first-post', $post->slug);
     // Bob's second post with same title is made unique
     $post = new PostWithUniqueSlugConstraints(['title' => 'My first post']);
     $post->author()->associate($authorBob);
     $post->save();
     $this->assertEquals('my-first-post-1', $post->slug);
     // Pam's first post with same title is scoped to her
     $post = new PostWithUniqueSlugConstraints(['title' => 'My first post']);
     $post->author()->associate($authorPam);
     $post->save();
     $this->assertEquals('my-first-post', $post->slug);
     // Pam's second post with same title is scoped to her and made unique
     $post = new PostWithUniqueSlugConstraints(['title' => 'My first post']);
     $post->author()->associate($authorPam);
     $post->save();
     $this->assertEquals('my-first-post-1', $post->slug);
 }
Example #2
0
 /**
  * Test generating slug from related model field.
  *
  * @test
  */
 public function testSlugFromRelatedModel()
 {
     $author = Author::create(['name' => 'Arthur Conan Doyle']);
     $post = new PostWithRelation(['title' => 'First']);
     $post->author()->associate($author);
     $post->save();
     $this->assertEquals('arthur-conan-doyle-first', $post->slug);
 }