TextbookCatalog.php 962 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. namespace App\Models;
  3. use Illuminate\Database\Eloquent\Model;
  4. class TextbookCatalog extends Model
  5. {
  6. protected $table = 'textbook_catalog_nodes';
  7. protected $fillable = [
  8. 'textbook_id',
  9. 'parent_id',
  10. 'node_type',
  11. 'title',
  12. 'display_no',
  13. 'depth',
  14. 'sort_order',
  15. 'path_key',
  16. 'is_required',
  17. 'is_elective',
  18. 'tags',
  19. 'page_start',
  20. 'page_end',
  21. 'meta',
  22. ];
  23. protected $casts = [
  24. 'is_required' => 'boolean',
  25. 'is_elective' => 'boolean',
  26. // 移除 array cast,直接使用 JSON 字符串
  27. ];
  28. public function textbook()
  29. {
  30. return $this->belongsTo(Textbook::class);
  31. }
  32. public function parent()
  33. {
  34. return $this->belongsTo(self::class, 'parent_id');
  35. }
  36. public function children()
  37. {
  38. return $this->hasMany(self::class, 'parent_id')->orderBy('sort_order');
  39. }
  40. }