Tutorial.php 434 B

123456789101112131415161718192021222324
  1. <?php
  2. namespace App;
  3. use Illuminate\Database\Eloquent\Model;
  4. class Tutorial extends Model
  5. {
  6. protected $fillable=[
  7. 'owner_id','name','content','type'
  8. ];
  9. protected $appends=[
  10. 'owner_name'
  11. ];
  12. public function owner(){
  13. return $this->belongsTo('App\Owner','owner_id','id');
  14. }
  15. public function getOwnerNameAttribute()
  16. {
  17. $this['owner']? $this['owner']['name']:null;
  18. }
  19. }