Initial commit

This commit is contained in:
Richard Jolley committed 2026-01-14 00:54:08 +00:00
commit c909d539bc
7178 files changed
+756624

No files matched your search

+51
View File
@@ -0,0 +1,51 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Str;
class LessonSection extends Model
{
protected $fillable = ['module_id', 'title', 'year', 'order', 'slug'];
public function module()
{
return $this->belongsTo(Module::class);
}
public function lessons()
{
return $this->hasMany(Lesson::class)->orderBy('order');
}
public function chapters()
{
return $this->hasMany(Chapter::class)->orderBy('order');
}
public function getRouteKeyName()
{
return 'slug';
}
protected static function boot()
{
parent::boot();
static::creating(function ($section) {
if (empty($section->slug)) {
// Use title + uniqid to avoid collisions
$section->slug = Str::slug($section->title . '-' . uniqid());
}
});
static::updating(function ($section) {
if ($section->isDirty('title')) {
// When renaming, regenerate slug based on title + id
$section->slug = Str::slug($section->title . '-' . $section->id);
}
});
}
}