parent
5087724847
commit
e47dea7936
|
@ -10,6 +10,7 @@ use Database\Factories\FormFactory;
|
||||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||||
|
use Illuminate\Support\Str;
|
||||||
use Spatie\Sluggable\HasSlug;
|
use Spatie\Sluggable\HasSlug;
|
||||||
use Spatie\Sluggable\SlugOptions;
|
use Spatie\Sluggable\SlugOptions;
|
||||||
use Stevebauman\Purify\Facades\Purify;
|
use Stevebauman\Purify\Facades\Purify;
|
||||||
|
@ -245,7 +246,9 @@ class Form extends Model
|
||||||
{
|
{
|
||||||
return SlugOptions::create()
|
return SlugOptions::create()
|
||||||
->doNotGenerateSlugsOnUpdate()
|
->doNotGenerateSlugsOnUpdate()
|
||||||
->generateSlugsFrom('title')
|
->generateSlugsFrom(function (Form $form) {
|
||||||
|
return $form->title . ' ' . Str::random(6);
|
||||||
|
})
|
||||||
->saveSlugsTo('slug');
|
->saveSlugsTo('slug');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -86,7 +86,9 @@ it('can regenerate a form url', function () {
|
||||||
->assertSuccessful()
|
->assertSuccessful()
|
||||||
->assertJson(function (AssertableJson $json) use ($newSlug) {
|
->assertJson(function (AssertableJson $json) use ($newSlug) {
|
||||||
return $json->where('type', 'success')
|
return $json->where('type', 'success')
|
||||||
->where('form.slug', $newSlug)
|
->where('form.slug', function ($slug) use ($newSlug) {
|
||||||
|
return substr($slug, 0, -6) == substr($newSlug, 0, -6);
|
||||||
|
})
|
||||||
->etc();
|
->etc();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue