Skip to content
This repository has been archived by the owner on Mar 14, 2020. It is now read-only.

Commit

Permalink
added slug
Browse files Browse the repository at this point in the history
  • Loading branch information
davidhsianturi committed Feb 23, 2018
1 parent 597ea69 commit a9fb8e2
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 10 deletions.
26 changes: 18 additions & 8 deletions app/Models/Doctor/Doctor.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,17 @@ class Doctor extends Model
'group_id',
'speciality_id',
'full_name',
'slug',
'years_of_experience',
'qualification',
'bio',
'is_active',
];

// public function getRouteKeyName()
// {
// return 'name';
// }
public function getRouteKeyName()
{
return 'slug';
}

public function user()
{
Expand Down Expand Up @@ -54,8 +55,17 @@ public function healthHistory()
return $this->hasMany('App\Models\Patient\HealthHistory');
}

// public function scopeFilter($query, $filters)
// {
// return $filters->apply($query);
// }
public function setSlugAttribute($value)
{
if (static::whereSlug($slug = str_slug($value))->exists()) {
$slug = "{$slug}-{$this->id}";
}

$this->attributes['slug'] = $slug;
}

public function scopeFilter($query, $filters)
{
return $filters->apply($query);
}
}
7 changes: 5 additions & 2 deletions database/factories/UserFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

// doctors
$factory->define(App\Models\Doctor\Doctor::class, function (Faker $faker) {
$full_name = $faker->name;

return [
'user_id' => function () {
return factory('App\User')->create()->id;
Expand All @@ -26,10 +28,11 @@
'speciality_id' => function () {
return factory('App\Models\Setting\Speciality\Speciality')->create()->id;
},
'full_name' => $faker->name,
'full_name' => $full_name,
'slug' => str_slug($full_name),
'years_of_experience' => '10',
'qualification' => 'MBBS, MS',
'bio' => $faker->word,
'bio' => $faker->sentence,
'is_active' => true,
];
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public function up()
$table->unsignedInteger('group_id');
$table->unsignedInteger('speciality_id')->nullable();
$table->string('full_name')->nullable();
$table->string('slug')->unique()->nullable();
$table->smallInteger('years_of_experience')->nullable();
$table->string('qualification')->nullable();
$table->string('bio')->nullable();
Expand Down

0 comments on commit a9fb8e2

Please sign in to comment.