Initial commit
This commit is contained in:
commit
c909d539bc
7178 files changed
+756624
No files matched your search
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class Chapter extends Model
|
||||
{
|
||||
protected $fillable = ['lesson_section_id', 'title', 'order'];
|
||||
|
||||
public function lessonSection()
|
||||
{
|
||||
return $this->belongsTo(LessonSection::class);
|
||||
}
|
||||
|
||||
public function lessons()
|
||||
{
|
||||
return $this->hasMany(Lesson::class)->orderBy('order');
|
||||
}
|
||||
|
||||
protected static function booted()
|
||||
{
|
||||
static::creating(function ($chapter) {
|
||||
if (empty($chapter->slug)) {
|
||||
$chapter->slug = Str::slug($chapter->title);
|
||||
}
|
||||
});
|
||||
|
||||
static::updating(function ($chapter) {
|
||||
if ($chapter->isDirty('title')) {
|
||||
$chapter->slug = Str::slug($chapter->title);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public function getRouteKeyName()
|
||||
{
|
||||
return 'slug';
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user