# Một ví dụ sử dụng làm mẫu code (ok)✌️✌️✌️

![](https://1957079826-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MCBeDUD-PK_RF-YgJRe%2Fuploads%2FSwJj5s1dGkpZd7VkxGdH%2FScreenshot_1.png?alt=media\&token=9b1452e8-9d64-45b6-b29a-ac7a96f2874f)

![](https://1957079826-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MCBeDUD-PK_RF-YgJRe%2Fuploads%2FPPUSOr88GaLmirDZOwQy%2FScreenshot_2.png?alt=media\&token=0658fb64-e66a-4178-bf0b-fc13b830fefe)

![](https://1957079826-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MCBeDUD-PK_RF-YgJRe%2Fuploads%2Fb1E7j1NybEasWSn7R9Xk%2FScreenshot_3.png?alt=media\&token=98fc27d0-faff-413a-b20b-e373967153bd)

![](https://1957079826-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MCBeDUD-PK_RF-YgJRe%2Fuploads%2FRn7bhrIesWVFFouhNzLP%2FScreenshot_5.png?alt=media\&token=eea6ca87-cf34-410c-8e36-0ee6eb821f45)

![](https://1957079826-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MCBeDUD-PK_RF-YgJRe%2Fuploads%2FEPhN3FWfVEfEOAo5lR77%2FScreenshot_4.png?alt=media\&token=0542bbf4-cef1-4fb1-bd08-c1b9d4af7308)

C:\xampp\htdocs\book\app\Models\Truyen.php

```
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Truyen extends Model {
  use HasFactory;
  public $timestamps = false;
  /**
   * The table associated with the model.
   *
   * @var string
   */
  protected $table = 'truyen';
  /**
   * The primary key associated with the table.
   *
   * @var string
   */
  protected $primaryKey = 'id';
  /**
   * The attributes that are mass assignable.
   *
   * @var array
   */
  protected $fillable = ['tentruyen', 'slug_truyen', 'kichhoat', 'tomtat', 'hinhanh', 'danhmuc_id', 'tacgia', 'tukhoa'];
  /**
   * The attributes that are mass assignable.
   *
   * @var array
   */
  public function danhmuctruyen() {
    return $this->belongsTo('App\Models\Danhmuc', 'danhmuc_id', 'id');
  }
  /**
   * The attributes that are mass assignable.
   *
   * @var array
   */
  public function theloai() {
    return $this->belongsTo('App\Models\Theloai', 'theloai_id', 'id');
  }
  /**
   * The attributes that are mass assignable.
   *
   * @var array
   */
  public function thuocnhieudanhmuctruyen() {
    return $this->belongsToMany(Danhmuc::class, 'thuocdanh', 'truyen_id', 'danhmuc_id');
  }
  /**
   * The attributes that are mass assignable.
   *
   * @var array
   */
  public function thuocnhieutheloaitruyen() {
    return $this->belongsToMany(Theloai::class, 'thuocloai', 'truyen_id', 'theloai_id');
  }
  /**
   * The attributes that are mass assignable.
   *
   * @var array
   */
  public function chapter() {
    return $this->hasMany('App\Models\Chapter', 'truyen_id', 'id');
  }
}
```
